[go: up one dir, main page]

0% found this document useful (0 votes)
17 views7 pages

Unit Ii

PROBLEM SOLVING WITH PYTHON
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

Unit Ii

PROBLEM SOLVING WITH PYTHON
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

GE8151 PROBLEM SOLVING AND PYTHON

https://www.poriyaan.in/
PROGRAMMING https://eee.poriyaan.in/
UNIT – II
DATA, EXPRESSIONS, STATEMENTS

/
in
PART-A
Problem Solving and Python Programming
1. What is meant by interpreter?

n.
An interpreter reads a high-level program and executes it. It takes single

aa
instruction as input and executes one line at a time. Errors are displayed for every
instruction.

riy
Example: Python, java.

2. Define the two modes in Python.

o
.p
➢ Iterative Mode: It allows writing codes in python command prompt. The
Chevron >>> is the prompt used by the interpreter to indicate that it is ready to
w
accept input. Here code will produce immediate results. It is useful to test small
codes.
w
➢ Script Mode: It is a text file containing the python statements. In this mode
python program is typed in a file and then using interpreter it will be executed to get
//w

the output. It can be used and again for execution.


3. List down the basic data types in python. / Name the four types of scalar objects
s:

python has.
tp

➢ Number
➢ String
ht

➢ List
➢ Tuple
➢ Dictionary

4. Define Keyboard and Enumerate some of the keywords in pythons.

A keyword is a reserved word that has special meaning. It cannot be used as


identifiers. Python has 33 keywords.

Example: and, if, elif, while, for, is, continue

5. Define a variable and write down the rules for naming variable.
Variable is a name that refers to a value. When a variable is created it will
allocate some memory space to store values in memory.

• Identifiers must start with alphabet or an underscore ( _ )


• It should not start with numbers.
• Keywords cannot be used as identifiers.
• It is case-sensitive.
https://www.poriyaan.in/• Identifier can be of any length https://eee.poriyaan.in/

6. Define an expression with Example.

An expression is a combination of values, variables, and operators. An

/
in
expression is evaluated using assignment operator.

n.
Example: Y=X+17

aa
7. Define statement and mention the difference between statement and an
expression.

iy
Instruction that a python interpreter can execute are called statement. A statement is
a unit of code like creating a variable or displaying a value. The important difference is

or
that an expression has a value but a statement does not have a value.

.p
8. Outline the logic to swap the contents of two identifiers without using third
variables.
w
Program:
w
x=10
y=20
//w

x,y=y,x
print(“Value of x=*x)
print(“Value of y=*y)
s:

Output:
Value of x=20
tp

Value of y=10
ht

9. List down the different types of operator.

• Arithmetic operator
• Relational operator
• Assignment operator
• Logical operator
• Bitwise operator
• Membership operator
• Identity operator

10. State about logical operator available in python language with example.

Logical operators are used to check two or more conditions at the same time. It returns
Boolean value.
• And-if all conditions are True it means True otherwise False.
• Or-if any one of the conditions is True it returns True otherwise False.
• Not-if the input is true output will be false and vice-versa.

11. What do you mean by an operand and an operator? Illustrate your answer with
relevant Example.

An operator is a symbol used to perform operation on the operands. Operands are


variables or values to which operation must be performed.

/
in
Example: a+20*b-32
In this example: a,b, 20 and 32 are operand and +,* and – are operators.

n.
12. What is meant by rule of precedence? Give the order of precedence.

aa
The set of rules that govern the order in which expressions involving multiple

riy
operators and operands are evaluated is known as rule of precedence. “PEMDAS” is
an acronym used to remember the precedence of operators. Parentheses have the
highest precedence followed by exponentiation. Multiplication and division have the

o
next highest precedence followed by addition and subtraction.

13. What is the use of parantheses? .p


w
Parentheses have the highest precedence and can be used to evaluate an
w
expression in the order you want. Using this associativity of operators can be changed.
It also makes an expression easier to read.
//w

Example: [2+5)-12/4*7

14. Compose the importance of indentation in python.


s:

In python language, indentation is used to determine the structure instead of


using braces. A block defined using indentation and ends with unindentation. It makes
tp

reader to be comfortable enough to go through the program and understand the


meaning.
ht

15. What is the purpose of using comment in python program?

Comment statements are used to add additional information about a program or a


statement to explain it in Natural language. It starts with hash symbol #. When python
interpreter see # sign it ignores all the text after # sign till the end of that line.
Example: ans =l*b #it calculates area of Rectangle

16. Define function.

Functions are set of related statements that will perform a specific task. It helps to
break the program into small units. It makes program small by eliminating repetitive
codes. Small parts of program can be debugged and tested separately.
17. State the reasons to divide programs into functions.
It makes program small by eliminating repetitive codes provides Re-usability, Small
parts of program can be debugged and tested separately. The length of a program can be
reduced.
18. Define arguments and parameter.

/
Arguments- Values provided in function call are called as Arguments. It is also called

in
as Actual Arguments

n.
Parameters- Values provided in function call are called as Parameters. It is also called
as formal arguments.

aa
Example:
Def Add(x,y): #function Definition

iy
Print(x,y)
a=10

or
b=15
Add(a,b) #function call

.p
Here x and y are formal parameters. a and b are actual parameters.

19. What is a local variable?


w
A variable defined inside a function is called as local variable. It can only be
w

accessed, used and visible only within the function.


//w

Example:
Def Display();
s:

A=30 #Local Varia


Print (“Value of a = “,a)
tp

Display()
ht

Output: Value of a -30


20. What is a global variable?

Global variables are the one that are defined and declared outside a function. It can
only be accessed, used and visible anywhere in the program.
Example:
a=10 #Global Variable
def Display();
print(“Value of a=”,a)
Display()
Output: Value of a = 10
21. Comment with an example on the use of local and global variable with the same
identifier name.
https://www.poriyaan.in/ https://eee.poriyaan.in/
A variable defined inside a function is called as local variable. It can only be
accessed, used and visible only within the function.
Example:
a=10 #Global Variable

/
def Display();

in
a=30 #Local Variable

n.
Print(“Value of a inside function=”,a)
Display()
Print(“Value of a outside function=”,a)

aa
Output:
Value of a inside function = 30

riy
Value of a outside function = 10

o
.p
w
w
//w
s:
tp
ht
Problem Solving and Python Programming (GE3151) – Reg 2021
Unit I: Computational Thinking and Problem Solving
Computational Thinking and Problem Solving | Fundamentals of Computing | Identification of Computational Problems |
Algorithms | Building Blocks | Notation | Algorithmic Problem Solving | Simple Strategies for Developing Algorithms |
Illustrative Problems | Anna University Two Marks Questions & Answers | Multiple Choice Questions and Answers

Unit II: Data Types, Expressions, Statements


Data Types, Expressions, Statements | Introduction to Python | How to Write and Execute Python Program | Concept
of Interpreter and Compiler | Python Interpreter | Interactive and Script Modes | Debugging | Values and Types |
Variables, Expressions and Statements | Tuple Assignment | Indentation, String Operations | Functions | Illustrative
Programs | Anna University Two Marks Questions & Answers | Multiple Choice Questions

Unit III: Control Flow, Functions, Strings


Control Flow, Functions, Strings | Boolean Values | Operators | Input and Output | Conditional Statements | Iteration
| Fruitful Functions | Recursion | Strings | Lists as arrays | Illustrative Programs | Anna University Two Marks
Questions & Answers | Multiple Choice Questions

Unit IV: Lists, Tuples, Dictionaries


Lists, Tuples, Dictionaries | Lists | Tuples | Dictionaries | Advanced List Processing - List Comprehension | Illustrative
Programs | Anna University Two Marks Questions & Answers | Multiple Choice Questions

Unit V: Files, Modules, Packages


Files, Modules, Packages | Files | Command Line Arguments | Errors and Exceptions | Modules | Packages | Two Marks
Questions with Answers | Multiple Choice Questions

Common to all 1st Semester

HOME | EEE | ECE | MECH | CIVIL | CSE


1st Semester Anna University EEE- Reg 2021
Professional English – I
2nd Semester 3rd Semester
Matrices and Calculus
Probability and Complex
Professional English - II Functions
Engineering Physics
Statistics and Numerical Electromagnetic Fields
Engineering Chemistry Methods
Problem Solving and Physics for Electrical Digital Logic Circuits
Python Programming Engineering
Electron Devices and
Physics and Chemistry Basic Civil and Mechanical Circuits
Laboratory Engineering
Electrical Machines - I
Engineering Graphics
C Programming and Data
4th Semester Electric Circuit Analysis Structures
Environmental Sciences
and Sustainability 6th Semester
Transmission and 5th Semester
Distribution Protection and
Linear Integrated Power System Analysis Switchgear
Circuits
Power Electronics Power System
Measurements and Operation and Control
Instrumentation Control Systems
Open Elective – I
Microprocessor and
Microcontroller Professional Elective I
Professional Elective IV
Electrical Machines - II Professional Elective II
Professional Elective V
Professional Elective III
7th Semester Professional Elective VI
High Voltage Mandatory Course-I& Mandatory Course-
Engineering II& MC
Human Values and 8th Semester
Ethics
Elective –
Management Project Work /
Internship
Open Elective – II
Open Elective – III
Open Elective – IV
Professional Elective
VII Click on Clouds to navigate other department

https://www.poriyaan.in/

You might also like