Professional Documents
Culture Documents
Python interpreter and interactive mode; values and types: int, float, boolean, string, and
list; variables, expressions, statements, tuple assignment, precedence of operators,
comments; modules and functions, function definition and use, flow of execution,
parameters and arguments; Illustrative programs: exchange the values of two variables,
circulate the values of n variables, distance between two points.
Introduction
Programming:
Program: A program is a sequence of instructions that specifies how to perform a
computation. The computation might be something mathematical, such as solving a
system of equations or finding the roots of a polynomial, but it can also be a symbolic
computation, such as searching and replacing text in a document or something graphical,
like processing an image or playing a video.
There are few basic instructions appear in every programming language:
input: Get data from the keyboard, a file, or some other device.
output: Display data on the screen or send data to a file or other device.
math: Perform basic mathematical operations like addition and multiplication.
conditional execution: Check for certain conditions and execute the appropriate
code.
repetition: Perform some action repeatedly, usually with some variation.
Characteristics of a Good Program: The following important characteristics should be
followed while writing a program.
Accuracy
Clarity
Efficiency
Modularity
User Friendly
Reliable
Portable
Programming language:
High-level languages are much easier to write and more problem oriented. Low-
level languages sometimes referred to as “machine languages” or “assembly languages.
Compiler is the software used to translate a complete program written in a high level
language into low level language. The high-level program is called the source code, and
the translated program is called the object code or the executable. Once a program is
compiled, we can execute it repeatedly without further translation. Interpreter is also
software; it reads the source code line by line and converts them into object code.
PYTHON:
Python is a general-purpose interpreted, interactive, object-oriented, and high-level
programming language. It was created by Guido van Rossum at National Research
Institute for Mathematics and Computer Science in Netherlands during 1985- 1990.
Python got its name from “Monty Python‟s flying circus”, which is a British comedy
series. Python was released in the year 2000.
Features:
Python is interpreted: Python is processed at runtime by the interpreter. No need
to compile Python program before executing it.
Python is Interactive: We can use Python prompt and interact with the interpreter
directly to write our programs.
Python is Object-Oriented: Python supports Object-Oriented style or technique
of programming that encapsulates code within objects.
Python is a Beginner's Language: Python is a great language for the beginner-
level programmers and supports the development of a wide range of applications.
Easy-to-learn: Python is clearly defined and easily readable. The structure of the
program is very simple. It uses few keywords.
Easy-to-maintain: Python's source code is fair.
Portable: Python can run on a wide variety of hardware platforms and has the
same interface on all platforms.
Interpreted: Python is processed at runtime by the interpreter. So, there is no
need to compile a program before executing it. We can simply run the program.
Extensible: Programmers can embed python within their C, C++, Java script,
ActiveX, etc.
Free and Open Source: Anyone can freely distribute it, read the source code, and
edit it.
High Level Language: When writing programs, programmers concentrate on
solutions of the current problem, no need to worry about the low level details.
Scalable: Python provides a better structure and support for large programs than
shell scripting.
Application:
Embedded scripting language
3D software
Web Development
Image processing and graphic Design Application
GUI based desktop application
Science and Computational application
Games
Advantages of python:
Readability: If the software has a highly readable code, then it is easier to
maintain.
Portability: Platform independent.
Vast support of libraries: It has large collection of in-built functionalities.
Software integration: It can easily extend, communicate and integrate with other
languages.
Developer productivity: It is a dynamically typed language i.e., no need to declare
variables explicitly.
Python programs run immediately i.e., without taking much time to link and
compile.
IDLE: Integrated Development and Learning Environment.
The IDLE tool is included in python‟s installation package. It offers more efficient
platform for write code and work interactively with python. We can access IDLE on the
same folder or command line icon or on the start menu. By clicking on the IDLE icon, it
displays the python shell window. It comprises of python shell (allows users to access
different features of IDLE through its drop down menu) and python editor (allows us to
work in script mode).
Features of IDLE:
Multi-window text editor with syntax highlighting.
Python Interpreter: It is a program that reads and executes Python code. It uses 2
modes of Execution.
1. Interactive mode
2. Script mode
1. Interactive mode: Interactive Mode, as the name suggests, allows us to interact with
OS.
When we type Python statement, interpreter displays the result(s) immediately.
Eg: >>> 1 + 1
2
The chevron, >>>, is the prompt the interpreter uses to indicate that it is ready for us to
enter code. If we type 1 + 1, the interpreter replies 2.
2. Script mode: In script mode, we type python program in a file and then use interpreter
to execute the content of the file. Scripts can be saved to disk for future use. Python
scripts have the extension .py (meaning that the filename ends with .py).
We can save the code with filename.py and run the interpreter in script mode to execute
the script.
In a file filename.py
Print(1) Output
x=2 >>>1
print(x) 2
use and we have to retype all the statements and we no need to retype all the statements
to re-run them. to re-run them.
We can see the results immediately. We can‟t see the results immediately.
>>>type('Hello,
World!') <type 'str'>
>>>type(17)
<type 'int'>
>>>type('17')
<type 'str'>
>>>type('3.2')
<type 'str'>
Numbers:
Number data type stores Numerical Values. This data type is immutable [i.e.
values/items cannot be changed]. Python supports integers, floating point numbers and
complex numbers. They are defined as,
Mr. P. J. Merbin Jose
6
Boolean
It has values either True or False. Internally true value represented as 1 and false as 0. It
is used to compare two values.
Eg:
>>>4==8
False
>>>4<8
True
Sequence:
A sequence is an ordered collection of items, indexed by positive integers. It is a
combination of mutable (value can be changed) and immutable (values cannot be
changed) data types.
There are three types of sequence data type available in Python, they are
7
1. String
2. List
3. Tuple
String
A String in Python consists of a series or sequence of characters - letters, numbers, and
special characters. Strings are marked by quotes:
single quotes (' ') Eg, 'This a string in single quotes'
double quotes (" ") Eg, "'This a string in double quotes'"
triple quotes (""" """) Eg, This is a paragraph. It is made up of multiple lines and
sentences.""”
Individual character in a string is accessed using a subscript (index). Characters can
be accessed using indexing and slicing operations. Strings are immutable i.e. the contents
of the string cannot be changed after it is created.
String is sequence of Unicode characters. We can use single quotes or double quotes
to represent strings. Multi-line strings can be denoted using triple quotes, ''' or """.
Eg:
>>> s = "This is a string"
>>> s = „‟‟a multiline‟‟‟
The str function is used to convert a number into a string.
>>>str(34.23)
‟34.23‟
List
List is an ordered sequence of items. Values in the list are called elements / items.
It can be written as a list of comma-separated items (values) between square
brackets [ ].
Items in the lists can be of different data types.
Eg:
>>> a = [‟spam‟, ‟eggs‟, 100, 1234]
>>> a
Output: [‟spam‟, ‟eggs‟, 100, 1234]
We can use a list‟s constructor to create a list.
Create an empty list L1=list()
Create a list with any integers L2=list([3,5,2])
Create a list using built-in range L3=list(range(0,5)). Creates a list with elements from 0
to 5.
Tuple:
A tuple is same as list, except that the set of elements is enclosed in parentheses instead
of square brackets.
8
A tuple is an immutable list. i.e., once a tuple has been created, we can't add elements
to a tuple or remove elements from the tuple.
Benefit of Tuple:
Tuples are faster than lists.
If the user wants to protect the data from accidental changes, tuple can be used.
Tuples can be used as keys in dictionaries, while lists can't.
Eg:
Tuple with string values
>>>T= („sun‟,‟mon‟,‟tue‟)
>>>print T
(„sun‟,‟mon‟,‟tue‟)
Dictionaries:
Lists are ordered sets of objects, whereas dictionaries are unordered sets.
Dictionary is created by using curly brackets. i,e. {}
Dictionaries are accessed via keys and not via their position.
A dictionary is an associative array (also known as hashes). Any key of the
dictionary is associated (or mapped) to a value.
The values of a dictionary can be any Python data type. So dictionaries are
unordered key-value-pairs(The association of a key and a value is called a key-
value pair )
Dictionaries don't support the sequence operation of the sequence data types like
strings, tuples and lists.
Eg:
9
Variables
A variable is a name that refers to a value. A variable is a location in memory used
to store some data (value). They are given unique names to differentiate between
different memory locations. The assignment operator (=) to assign values to a variable.
An assignment statement creates new variables and gives them values:
Rules for naming variables:
Variable names can be uppercase letters or lower case letters.
Variable names can be at any length
They can contain both letters and numbers, but they can‟t begin with a
number.
The underscore ( _ ) character can appear in a name. It is often used in
names with multiple words.
Eg:my_name
No blank spaces are allowed between variable name.
A variable name cannot be any one of the keywords or special characters.
Variable names are case-sensitive
Assigning value to variable:
Value should be given on the right side of assignment operator(=) and variable on left
side.
10
>>> a=2
>>> a+3+2
7
>>> z=("hi"+"friend")
>>> print(z)
hifriend
Statements:
Instructions that a Python interpreter can execute are called statements. A
statement is a unit of code that the Python interpreter can execute. Two kinds of
statement: print and assignment.
Eg:
>>> n = 17
>>> print(n)
Here, the first line is an assignment statement that gives a value to n. The second line is a
print statement that displays the value of n.
Eg:
a=1+2+3+\
4+5+6+\
7+8+9
In Python, end of a statement is marked by a newline character. But we can make
a statement extend over multiple lines with the line continuation character (\).
Python Indentation
Most of the programming languages like C, C++, Java use braces { } to define a
block of code. Python uses indentation.
A code block (body of a function, loop etc.) starts with indentation and ends with
the first unindented line. The amount of indentation is up to you, but it must be consistent
throughout that block. Generally four whitespaces are used for indentation and is
preferred over tabs. Here is an example.
Python Tuple
Tuple is an ordered sequence of items same as list. The only difference is that
tuples are immutable. Tuples once created cannot be modified.
12
Tuples are used to write-protect data and are usually faster than list as it cannot
change dynamically. It is defined within parentheses () where items are separated by
commas.
Eg:
>>> t = (5,'program', 1+3j)
>>> a=(5,7.9,10)
Tuple assignment
An assignment to all of the elements in a tuple using a single assignment
statement.
Python has a very powerful tuple assignment feature that allows a tuple of
variables on the left of an assignment to be assigned values from a tuple on the
right of the assignment.
The left side is a tuple of variables; the right side is a tuple of values.
Each value is assigned to its respective variable.
All the expressions on the right side are evaluated before any of the assignments.
This feature makes tuple assignment quite versatile.
Naturally, the number of variables on the left and the number of values on the
right have to be the same.
Examples:
>>> T1=(10,20,30)
>>> T2=(100,200,300,400)
>>>print T1
(10,20,30)
>>>print T2
(100,200,300,400)
>>>T1,T2=T2,T1
>>>print T1
(100,200,300,400)
>>>Print T2
(10,20,30)
'George'
>>> age
25
>>> salary
'20000'
The right side can be any kind of sequence (string, list, tuple)
>>> (a, b, c, d) = (1, 2, 3)
ValueError: need more than 3 values to unpack
Comments
Comments indicate Information in a program that is meant for other programmers
(or anyone reading the source code) and has no effect on the execution of the program. In
Python, we use the hash (#) symbol to start writing a comment.
Eg:
#This is a comment
#print out Hello
print('Hello')
Input and output
INPUT: Input is data entered by user (end user) in the program. In python, input ()
function is available for input.
Python accepts string as default data type. Conversion may require for all other types.
Syntax:
print (expression/constant/variable)
print (“Statement”,variable_name)
PRECEDENCE OFOPERATORS
OPERATORS:
An operator is a symbol that represents an operation performed on one or more operands.
An operand is a quantity on which an operation is performed.
Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operands and + is called
operator.
Types of Operators:
Python language supports the following types of operators
Arithmetic Operators
Comparison (Relational) Operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
1. Arithmetic operators
Arithmetic operators are used to perform mathematical operations like
addition, subtraction, multiplication etc.
Operator Meaning Example
+ Add two operands or unary plus x+y
- Subtract right operand from the left or unary minus x-y
* Multiply two operands x*y
/ Divide left operand by the right one (always results into x/y
float)
% Modulus - remainder of the division of left operand by x % y
the right
// Floor division – division of operands where the result is x//y
the quotient in which the digits after the decimal points
are removed.
** Exponent - left operand raised to the power of right x**y
# Output: x ** y = 50625
print('x ** y =',x**y)
15
Examples Output:
a=10 a+b= 15
b=5 a-b= 5
print("a+b=",a+b) a*b= 50
print("a-b=",a-b) a/b= 2.0
print("a*b=",a*b) a%b= 0
print("a/b=",a/b) a//b= 2
print("a%b=",a%b) a**b= 100000
print("a//b=",a//b)
print("a**b=",a**b)
Example Output:
a=10 a>b=> True
b=5 a>b=> False
print("a>b=>",a>b) a==b=> False
print("a<b=>",a<b) a!=b=> True
print("a==b=>",a==b) a>=b=> False
print("a!=b=>",a!=b) a>=b=> True
print("a<=b=>",a<=b)
print("a>=b=>",a>=b)
Logical operators: Logical operators are used to compare and evaluate logical
operations. Python supports three logical operators: and, or, not
Bitwise operators: Bitwise operators act on operands as if they were string of binary
digits. It operates bit by bit, hence the name.
Example Output
a = 60 # 60 = 00111100 Line 1 - Value of c is 12
b = 13 # 13 = 0000 1101 Line 2 - Value of c is 61
c=0 Line3 - Value of c is 49
c=a&b #12= 0000 1100 Line 4 -Value of c is -61
print "Line 1 - Value of c is ", c Line 5- Value of c is 240
Line 6 - Value of c is 15
c = a | b; # 61 = 0011 1101
print "Line 2 - Value of c is ", c
c = a ^ b; # 49 = 0011 0001
print "Line 3 - Value of c is ", c
Assignment operators
Assignment operators are used in Python to assign values to variables. a = 5 is a simple
assignment operator that assigns the value 5 on the right to the variable a on the left.
There are various compound operators in Python like a += 5 that adds to the
variable and later assigns the same. It is equivalent to a = a + 5.
Operator Description Example
= Assigns values from right side c = a + b Assigns
operands to left side operand value of a+ b into c
Example
a = 21
b = 10
c=0
c=a+b
print("Line 1 - Value of c is ", c)
c += a
print("Line 2 - Value of c is ", c)
c *= a
print("Line 3 - Value of c is ", c)
c /= a
print("Line 4 - Value of c is ", c)
c = 2 c %= a
print("Line 5 - Value of c is ", c) c **= a
print("Line 6 - Value of c is ", c) c //= a
print("Line 7 - Value of c is ", c)
Output
Line 1 - Value of c is 31
Line 2 - Value of c is 52
Line 3 - Value of c is 1092
Line 4 - Value of c is 52.0
Line 5 - Value of c is 2
Line 6 - Value of c is 2097152
Line 7 - Value of c is 99864
Special operators: Python language offers some special type of operators like the
identity operator or the membership operator.
Identity operators
is and is not are the identity operators in Python. They are used to check if two
values (or variables) are located on the same part of the memory. Two variables that are
equal, does not imply that they are identical.
Operator Meaning
is True if the operands are identical(refer to the same object)
is not True if the operands are not identical(do not refer to the
same object)
y2 = 'Hello'
x3 = [1,2,3]
y3 = [1,2,3]
# Output: False
print(x1 is not y1)
# Output: True
print(x2 is y2)
# Output: False
print(x3 is y3)
Here, we see that x1 and y1 are integers of same values, so they are equal as well as
identical. Same is the case with x2 and y2 (strings).
But x3 and y3 are list. They are equal but not identical. Since list are mutable (can be
changed), interpreter locates them separately in memory although they are equal.
Membership operators
in and not in are the membership operators in Python. They are used to test
whether a value or variable is found in a sequence (string, list, tuple, set and dictionary).
In a dictionary we can only test for presence of key, not the value.
Operator Meaning Example
In True if value/variable is 5 in x
found in the sequence
not in True if value/variable is not 5 not in x
found in the sequence
# Output: True
print('hello' not in x)
# Output: True
print(1 in y)
# Output: False
print('a' in y)
Here, 'H' is in x but 'hello' is not present in x (remember, Python is case sensitive).
Similarly, 1 is key and 'a' is the value in dictionary y. Hence, 'a' in y returns False.
20
Precedence of Operators
The order of evaluation depends on the rules of precedence. The acronym
PEMDAS is a useful way to remember the rules:
Examples:
A=9-12/3+3*2-1 A=2*3+4%5-3/2+6 find m=?
a=? A=6+4%5-3/2+6 m=-43||8&&0||-2
a=9-4+3*2-1 A=6+4-3/2+6 m=-43||0||-2
a=9-4+6-1 A=6+4-1+6 m=1||-2
a=5+6-1 A=10-1+6 m=1
a=11-1 A=9+6
a=10 A=15
a=2,b=12,c=1 a=2,b=12,c=1 a=2*3+4%5-3//2+6
d=a<b>c d=a<b>c-1 a=6+4-1+6
d=2<12>1 d=2<12>1-1 a=10-1+6
d=1>1 d=2<12>0 a=15
d=0 d=1>0
d=1
21
Once we import a module, we can reference or use to any of its functions or variables in
our code.
There is large number of standard modules available in python.
Standard modules can be imported the same way as we import our user- defined
modules.
Every module contains many functions.
To access one of the functions, we have to specify the name of the module and the name
of the function separated by dot. This format is called dot notation.
Syntax:
import module_name
module_name.function_name(variable)
• Example:
Importing Built_in Module Output
import math 5.0
x=math.sqrt(25)
print(x)
There are four ways to import a module in a program
import: It is simplest and most commonfrom import: It is used to get a specific
way to use modules in our code function in the code instead of complete
Example: file.
import math Example:
x=math.pi from math import pi
print("The value of pi is",x) x= pi
Output print("The value of pi is",x)
The value of pi is 3.141592653589793 Output
The value of pi is 3.141592653589793
import with renaming: we can import a import all: we can import all
module by renaming the module as our names(definitions) form a module using *
wish Example:
Example: from math import *
import math as m x= pi
x=m.pi print("The value of pi is",x)
print("The value of pi is",x) Output
Output The value of pi is 3.141592653589793
The value of pi is 3.141592653589793
22
Functions
Function is a sub program which consists of set of instructions used to perform a specific
task. A large program is divided into basic building blocks called function.
Need for Function:
• When the program is too complex and large they are divided into parts. Each part
is separately coded and combined into single program. Each subprogram is called
as function.
• Debugging, Testing and maintenance becomes easy when the program is divided
into subprograms.
• Functions are used to avoid rewriting same code again and again in a program.
• Function provides code re-usability
• The length of the program is reduced.
Types of function:
Functions can be classified into two categories:
1. User_defined function
2. Built_in function
Built in functions
Built in functions are the predefined functions i.e., already created and stored in
python.These built in functions are always available for usage and accessed by a
programmer. It cannot be modified. Some of the built in functions in python are abs(),
float(), help(), format(), input(), print() etc.,
• >>> max(5,2)
5
• >>> float(3)
3.0
• >>> min(8,9)
8
Type conversion
There are some built in functions in the python programming languages that can be
convert one type of data into another type. For example int(), float(), str()
Example:
int functions can take any number value and convert it into an integer
>>> int(4.7)
4
In this example a floating point number 4.7 that was converted to an integer number4 by
the int function
>>> int('college')
Trace back (most recent call last):
File "<pyshell#2>", line 1, in <module>
23
int('college')
Value Error: invalid literal for int() with base 10: 'college'
In this example a string was not a number and applied int function to it, got an error.
This means that a string is not a number so it cannot be converted to an integer.
Type Coercion
Implicit conversion is also known as type coercion, and is automatically done by the
interpreter. Type coercion is a process through which the python interpreter
automatically converts a value of one type into a value of another type according to the
requirement.
Example:
minute=59
>>> minute/60.0
0.9833333333333333
In this example we make the denominator a float number. The python interpreter
automatically converts the numerator into float and does the calculation.
Mathematical function
1. math
Python provides a math module that contains most of the familiar and important
mathematical functions.
Example:
>>> import math
>>> math.sqrt(4)
2.0
2. Date and Time
Python provides the built in modules time and calendar through which we can handle
date and time in several ways. For this we have to import time and calendar module.
>>> import calendar
>>> c=calendar.month(2019,9)
>>> print(c)
September 2019
Mo Tu We Th Fr Sa Su
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
24
3.help()
It is used to invoke the help system. It takes an object as an argument. It gives all the
detailed information about that objects.
>>> import math
>>> help(math.sin)
<type 'int'>
The name of the function is type. The expression in parentheses is called the
argument of the function. The result is called the return value.
The return statement
The return statement is used to exit a function and go back to the place from where
it was called. The Syntax of return statement:
return [expression_list]
This statement can contain expression which gets evaluated and the value is returned. If
there is no expression in the statement or the return statement itself is not present inside a
function, then the function will return the None object.
For example:
>>> print(greet("May")) Hello, May. Good morning! None
Here, None is the returned value
Example:
Swapping two variables using function
def swap(a,b):
a,b=b,a
print("After Swap:")
print("First number:",a)
print("Second number:",b)
a=input("\n Enter the first number")
b=input("\n Enter the second number")
print("Before Swap:")
print("First number:",a)
print("Second number:",b)
swap(a,b)
Output:
Enter the first number30
27
o/p: o/p:
enter a 10 enter a 10
enter b 89 enter b 89
99 99
Parameters and Arguments
Parameters:
• Parameters are the value(s) provided in the parenthesis when we write function
header.
• These are the values required by function to work.
• If there is more than one value required, all of them will be listed in parameter list
separated by comma.
• Example: def add(a,b):
Arguments:
• Arguments are the value(s) provided in function call/invoke statement.
• List of arguments should be supplied in same way as parameters are listed.
• Bounding of parameters to arguments is done 1:1, and so there should be same
number and type of arguments as mentioned in parameter list.
• Example: add(x,y)
Illustrative Programs
1. Exchange the values of two variables (or) Swapping Output
of values
x=input(“Enter value of x:‟) Enter value of x: 55
y= input(“Enter value of y:‟) Enter value of y: 84
temp=x
x=y The value of x after swapping:84
y=temp The value of y after swapping:55
print(“ The value of x after swapping:”,x)
print(“ The value of y after swapping:”,y)
Additional programs:
Sl.No Programs Output
1. Python program to swap two variables Enter value of x: 45
(without temporary variable) Enter value of y: 80
# To take input from the user The value of x after swapping: 80
x = input('Enter value of x: ') The value of y after swapping: 45
y = input('Enter value of y: ')
# swap the values without using temporary
variable
x=x+y
y=x–y
x=x-y
print 'The value of x after swapping:‟,x
print 'The value of y after swapping:‟,y
print_row()
block()
block()
print_border()
4 Converting Centigrade to Fahrenheit Enter Celsius:30
C=int(input("Enter celsius:")) 30.0 degree Celsius equal to 86.0
F=C*1.8+32 degree Fahrenheit
print("%0.1f degree Celsius equal to %0.1f
degree Fahrenheit" %(C,F))
5 Converting Fahrenheit to centigrade Enter Fahrenheit 90
F=int(input("Enter Fahrenheit")) 90.0 degree Fahrenheit equal to
C=(F-32)*(5/9) 32.2 degree Celsius
print("%0.1f degree Fahrenheit equal to %0.1f
degree Celsius" %(F,C))
6 Area of a circle Enter Radius 10
from math import pi Area of the circle: 314.1592653589793
r=int(input("Enter Radius"))
area=pi*r*r
print("Area of the circle:",area)
print(num1,"- 2.substract
",num2,"=",substract(num1,num2)) 3.Multiply
elif choice=='3': 4.Division
Enter choices(1/2/3/4):3
print(num1,"*",num2,"=",multiply(num1,num2)) Enter first number:32
elif choice=='4': Enter second number:12
print(num1,"/",num2,"=",divide(num1,num2))32 * 12 = 384
else: Select operation
print("Invalid input") 1.Add
2.substract
3.Multiply
4.Division
Enter choices(1/2/3/4):4
Enter first number:300
Enter second number:12
300 / 12 = 25.0
Part B
1. Explain in detail about various data types in Python with an example?
2. Explain the different types of operators in python with an example.
3. Discuss the need and importance of function in python.
4. Explain in details about function prototypes in python.
5. Discuss about the various type of arguments in python.
6. Explain the flow of execution in user defined function with example.
7. Illustrate a program to display different data types using variables and literal constants.
8. Show how an input and output function is performed in python with an example.
9. Explain in detail about the various operators in python with suitable examples.
10. Discuss the difference between tuples and list
11. Discuss the various operation that can be performed on a tuple and Lists (minimum
5)with an example program
12. What is membership and identity operators.
13. Write a program to perform addition, subtraction, multiplication, integer division,
floor division and modulo division on two integer and float.
14. Write a program to convert degree Fahrenheit to Celsius
15. Discuss the need and importance of function in python.
16. Illustrate a program to exchange the value of two variables with temporary variables
17. Briefly discuss in detail about function prototyping in python. With suitable example
program
18. Analyze the difference between local and global variables.
19. Explain with an example program to circulate the values of n variables
20. Analyze with a program to find out the distance between two points using python.
21. Do the Case study and perform the following operation in tuples i) Maxima minima
iii)sum of two tuples iv) duplicate a tuple v)slicing operator vi) obtaining a list from a
tuple vii) Compare two tuples viii)printing two tuples of different data types
22. Write a program to find out the square root of two numbers