ArulmiguMeenakshi Amman College of Engineering
Vadamavandal-604410.
Important questions and answers
CS25C02-Computer Programming: Python
Prepared by
V.Umapathy,
Prof. /Mech.
S.No Question Answer
Syllabus
S.No. Describtion
1 Introduction to Python: Problem Solving, Problem Analysis Chart, Developing an
Algorithm, Flowchart and Pseudocode, Interactive and Script Mode, Indentation,
Comments, Error messages, Variables, Reserved Words, Data Types, Arithmetic
operators and expressions, Built-in Functions, Importing from Packages.
Practical: Problem Analysis Chart, Flowchart and Pseudocode Practices. (Minimum
three)
2 Control Structures: if, if-else, nested if, multi-way if-elif statements, while loop, for
loop, nested loops, pass statements.
Practical: Usage of conditional logics in programs. (Minimum three)
3 Functions: Hiding redundancy, complexity; Parameters, arguments and return
values; formal vs actual arguments, named arguments, Recursive & Lambda
Functions.
Practical: Usage of functions in programs. (Minimum three)
4 Strings & Collections: String Comparison, Formatting, Slicing, Splitting, Stripping,
Lists, tuples, and dictionaries, basic list operators, searching and sorting lists;
dictionary literals, adding and removing keys, accessing and replacing values.
Practical: String manipulations and operations on lists, tuples, sets, and dictionaries.
(Minimum three)
5 File Operations: Create, Open, Read, Write, Append and Close files. Manipulating
directories, OS and Sys modules, reading/writing text and numbers, from/to a file;
creating and reading a formatted file (csv, tab-separated, etc.).
Practical: Opening, closing, reading and writing in formatted file format and sort data.
(Minimum three)
6 Packages: Built-in modules, User-Defined modules, Numpy, SciPy, Pandas, Scikit-
learn.
Practical: Usage of modules and packages to solve problems. (Minimum three),
Project (Minimum Two)
, Unit-I
Introduction to Python
Introduction to Python
Python is a high-level, interpreted programming language that is widely used for various purposes
such as web development, scientific computing, data analysis, artificial intelligence, and more.
Problem Solving in Python
Problem solving in Python involves the following steps:
1. Problem Analysis: Identify the problem and understand the requirements.
2. Problem Analysis Chart: Create a chart to visualize the problem and identify the inputs, outputs,
and processing required.
3. Developing an Algorithm: Create a step-by-step solution to the problem.
4. Flowchart: Represent the algorithm graphically using a flowchart.
5. Pseudocode: Write the algorithm in a simplified language that is easy to understand.
Basic Concepts
- Interactive Mode: Python can be used in interactive mode, where you can execute commands
one by one.
- Script Mode: Python can also be used in script mode, where you write a script and execute it.
- Indentation: Python uses indentation to define the structure of the code.
- Comments: Comments are used to explain the code and are ignored by the interpreter.
- Error Messages: Python displays error messages when there is an error in the code.
- Variables: Variables are used to store values in Python.
- Reserved Words: Python has reserved words that cannot be used as variable names.
- Data Types: Python has various data types such as integers, floats, strings, lists, tuples, and
dictionaries.
Arithmetic Operators and Expressions
- Arithmetic Operators: +, -, , /, %, *, //
- Arithmetic Expressions: Expressions that involve arithmetic operators and operands.
Built-in Functions
,- print(): Prints the output to the screen.
- input(): Takes input from the user.
- len(): Returns the length of a string or list.
- type(): Returns the data type of a variable.
Importing from Packages
- import: Used to import modules from packages.
- from: Used to import specific functions or variables from a module.
Here is an example of a simple Python program:
# This is a comment
x = 5 # variable assignment
y = 3 # variable assignment
print(x + y) # prints 8
Common Data Types
- Integers: whole numbers, e.g. 1, 2, 3
- Floats: decimal numbers, e.g. 3.14, -0.5
- Strings: sequences of characters, e.g. 'hello', "hello"
- Lists: ordered collections of items, e.g. [1, 2, 3], ['a', 'b', 'c']
- Tuples: ordered, immutable collections of items, e.g. (1, 2, 3), ('a', 'b', 'c')
Example Use Cases
- Calculator Program:
x = int(input("Enter a number: "))
y = int(input("Enter another number: "))
print("Sum:", x + y)
print("Difference:", x - y)
print("Product:", x * y)
print("Quotient:", x / y)
- Simple Chatbot:
name = input("What is your name? ")
print("Hello, " + name + "!")
, Two mark Question and Answers
1. What is problem solving in Python?
Problem solving in Python is the process of identifying a problem, analyzing it, and
developing a solution using Python programming language.
2. What is a Problem Analysis Chart (PAC)?
A Problem Analysis Chart (PAC) is a tool used to analyze and understand a problem,
identifying inputs, outputs, and processing steps.
3. What is an algorithm?
An algorithm is a step-by-step procedure for solving a problem or achieving a specific goal.
4. What is the purpose of a flowchart?
A flowchart is a graphical representation of an algorithm, used to visualize the steps
involved in solving a problem.
5. What is pseudocode?
Pseudocode is a written representation of an algorithm, using a combination of natural
language and programming language-like syntax.
6. What are the two modes of using Python?
The two modes of using Python are Interactive Mode and Script Mode.
7. What is an error message in Python?
An error message in Python is a notification that something has gone wrong in the code,
indicating the type and location of the error.
8. What are reserved words in Python?
Reserved words in Python are words that have special meanings and cannot be used as
variable name.
9. What is the purpose of built-in functions in Python?
Built-in functions in Python are pre-defined functions that can be used to perform various
tasks, such as printing output or calculating mathematical functions.
10. How do you get user input in Python?
You can get user input in Python using the input() function.
13 and 15 Marks QA
11. Write a Python program to solve the following problem:
A company has a list of employees with their names, ages, and salaries. Write a
program to find the average salary of employees in each age group (20-29, 30-39, 40-
49, etc.).
Vadamavandal-604410.
Important questions and answers
CS25C02-Computer Programming: Python
Prepared by
V.Umapathy,
Prof. /Mech.
S.No Question Answer
Syllabus
S.No. Describtion
1 Introduction to Python: Problem Solving, Problem Analysis Chart, Developing an
Algorithm, Flowchart and Pseudocode, Interactive and Script Mode, Indentation,
Comments, Error messages, Variables, Reserved Words, Data Types, Arithmetic
operators and expressions, Built-in Functions, Importing from Packages.
Practical: Problem Analysis Chart, Flowchart and Pseudocode Practices. (Minimum
three)
2 Control Structures: if, if-else, nested if, multi-way if-elif statements, while loop, for
loop, nested loops, pass statements.
Practical: Usage of conditional logics in programs. (Minimum three)
3 Functions: Hiding redundancy, complexity; Parameters, arguments and return
values; formal vs actual arguments, named arguments, Recursive & Lambda
Functions.
Practical: Usage of functions in programs. (Minimum three)
4 Strings & Collections: String Comparison, Formatting, Slicing, Splitting, Stripping,
Lists, tuples, and dictionaries, basic list operators, searching and sorting lists;
dictionary literals, adding and removing keys, accessing and replacing values.
Practical: String manipulations and operations on lists, tuples, sets, and dictionaries.
(Minimum three)
5 File Operations: Create, Open, Read, Write, Append and Close files. Manipulating
directories, OS and Sys modules, reading/writing text and numbers, from/to a file;
creating and reading a formatted file (csv, tab-separated, etc.).
Practical: Opening, closing, reading and writing in formatted file format and sort data.
(Minimum three)
6 Packages: Built-in modules, User-Defined modules, Numpy, SciPy, Pandas, Scikit-
learn.
Practical: Usage of modules and packages to solve problems. (Minimum three),
Project (Minimum Two)
, Unit-I
Introduction to Python
Introduction to Python
Python is a high-level, interpreted programming language that is widely used for various purposes
such as web development, scientific computing, data analysis, artificial intelligence, and more.
Problem Solving in Python
Problem solving in Python involves the following steps:
1. Problem Analysis: Identify the problem and understand the requirements.
2. Problem Analysis Chart: Create a chart to visualize the problem and identify the inputs, outputs,
and processing required.
3. Developing an Algorithm: Create a step-by-step solution to the problem.
4. Flowchart: Represent the algorithm graphically using a flowchart.
5. Pseudocode: Write the algorithm in a simplified language that is easy to understand.
Basic Concepts
- Interactive Mode: Python can be used in interactive mode, where you can execute commands
one by one.
- Script Mode: Python can also be used in script mode, where you write a script and execute it.
- Indentation: Python uses indentation to define the structure of the code.
- Comments: Comments are used to explain the code and are ignored by the interpreter.
- Error Messages: Python displays error messages when there is an error in the code.
- Variables: Variables are used to store values in Python.
- Reserved Words: Python has reserved words that cannot be used as variable names.
- Data Types: Python has various data types such as integers, floats, strings, lists, tuples, and
dictionaries.
Arithmetic Operators and Expressions
- Arithmetic Operators: +, -, , /, %, *, //
- Arithmetic Expressions: Expressions that involve arithmetic operators and operands.
Built-in Functions
,- print(): Prints the output to the screen.
- input(): Takes input from the user.
- len(): Returns the length of a string or list.
- type(): Returns the data type of a variable.
Importing from Packages
- import: Used to import modules from packages.
- from: Used to import specific functions or variables from a module.
Here is an example of a simple Python program:
# This is a comment
x = 5 # variable assignment
y = 3 # variable assignment
print(x + y) # prints 8
Common Data Types
- Integers: whole numbers, e.g. 1, 2, 3
- Floats: decimal numbers, e.g. 3.14, -0.5
- Strings: sequences of characters, e.g. 'hello', "hello"
- Lists: ordered collections of items, e.g. [1, 2, 3], ['a', 'b', 'c']
- Tuples: ordered, immutable collections of items, e.g. (1, 2, 3), ('a', 'b', 'c')
Example Use Cases
- Calculator Program:
x = int(input("Enter a number: "))
y = int(input("Enter another number: "))
print("Sum:", x + y)
print("Difference:", x - y)
print("Product:", x * y)
print("Quotient:", x / y)
- Simple Chatbot:
name = input("What is your name? ")
print("Hello, " + name + "!")
, Two mark Question and Answers
1. What is problem solving in Python?
Problem solving in Python is the process of identifying a problem, analyzing it, and
developing a solution using Python programming language.
2. What is a Problem Analysis Chart (PAC)?
A Problem Analysis Chart (PAC) is a tool used to analyze and understand a problem,
identifying inputs, outputs, and processing steps.
3. What is an algorithm?
An algorithm is a step-by-step procedure for solving a problem or achieving a specific goal.
4. What is the purpose of a flowchart?
A flowchart is a graphical representation of an algorithm, used to visualize the steps
involved in solving a problem.
5. What is pseudocode?
Pseudocode is a written representation of an algorithm, using a combination of natural
language and programming language-like syntax.
6. What are the two modes of using Python?
The two modes of using Python are Interactive Mode and Script Mode.
7. What is an error message in Python?
An error message in Python is a notification that something has gone wrong in the code,
indicating the type and location of the error.
8. What are reserved words in Python?
Reserved words in Python are words that have special meanings and cannot be used as
variable name.
9. What is the purpose of built-in functions in Python?
Built-in functions in Python are pre-defined functions that can be used to perform various
tasks, such as printing output or calculating mathematical functions.
10. How do you get user input in Python?
You can get user input in Python using the input() function.
13 and 15 Marks QA
11. Write a Python program to solve the following problem:
A company has a list of employees with their names, ages, and salaries. Write a
program to find the average salary of employees in each age group (20-29, 30-39, 40-
49, etc.).