Professional Documents
Culture Documents
Python Lab File Mehulchawla A2305120007
Python Lab File Mehulchawla A2305120007
Introduction to Python
Code: ECE319
Submitted by
Mehul Chawla
A2305120014
5ECE1-X
Submitted to
Dr Rinki Gupta
Associate Professor
Date of
S. Category of Exp Name of Date of Max M. Signature of
Code Allotment of
No. Assignment No. Experiment Eval. M. Obt Faculty
Expt.
Mandatory
4. 4. 1
Experiment
Mandatory
5. 5. 1
Experiment
Mandatory LR
6. 6. 1
Experiment (10)
Mandatory
7. 7. 1
Experiment
Mandatory
8. 8. 1
Experiment
Mandatory
9. 9. 1
Experiment
Mandatory
10 10. 1
Experiment
EXPERIMENT 1
AIM: Write a program to read two integers and find the sum, difference, multiplication, and
division.
DESCRIPTION:
Arithmetic operators are used to perform mathematical operations like addition, subtraction,
multiplication, etc. Python Operators in general are used to perform operations on values
and variables. These are standard symbols used for the purpose of logical and arithmetic
operations. We will look into different types of Python operators.
OPERATORS: Are the special symbols. Eg- + , * , /, etc.
OPERAND: It is the value on which the operator is applied.
PROGRAM:
#Variable creation
var1=10
var2=5.5
print('var1=', var1)
print('var2=', var2)
#Addition
print(var1,'+',var2,'=',var1+var2)
Output: -
var1= 10
var2= 5.5
10 + 5.5 = 15.5
#Format1
print(var1,'+',var2,'=',var1+var2) #Addition
print(var1,'-',var2,'=',var1-var2) #Subtraction
print(var1,'*',var2,'=',var1*var2) #Multiplication
print(var1,'/',var2,'=',var1/var2) #Division
Output: -
10 + 5.5 = 15.5
10 – 5.5 = 4.5
10 * 5.5 = 55.0
10 / 5.5 = 1.81818181818181
#Format2
print('%d + %d = %d' %(var1,var2, var1+var2)) #Addition
Output: -
10 + 5.5 = 15.5
10 – 5.5 = 4.5
10 * 5.5 = 55.0
10 / 5.5 = 1.81818181818181
#Format3
Output: -
10 + 5.5 = 15.5
10 – 5.5 = 4.5
10 * 5.5 = 55.0
10 / 5.5 = 1.81818181818181
CONCLUSION:
The given experiment to read two integers and find the sum, difference,
multiplication, and division has been performed successfully.
Evaluation table:
TOTAL MARKS
CRITERIA COMMENTS
MARKS OBTAINED
Concept (A) 2
Implementation (B) 2
Performance (C) 2
TOTAL 6
EXPERIMENT 2
AIM: Write a python program to count the number of Characters in a given string and hence
to display the characters of string in reverse order.
DESCRIPTION:
In Python, you can get the length of a string str . (= number of characters) with the built-in
function len()
By passing a string to the built-in function len(), its length (number of characters) is returned
as an integer value.
Python String has got an in-built function – string.count() method to count the occurrence of
a character or a substring in the particular input string.
The string.count() method accepts a character or a substring as an argument and returns the
number of times the input substring happens to appear in the string.
Python String find() method returns the lowest index or first occurrence of the substring if it
is found in a given string. If it is not found then it returns -1.
PROGRAM:
#String input
name= input('Enter your Full name : ')
print(name)
Output: -
Enter your Full name : Mehul Chawla
Mehul Chawla
#Lower case
s1=name.lower();
print(s1)
Output: -
mehul chawla
#Reverse Order
print(s1[::-1]
Output: -
ALWAHC LUHEM
#Number of total characters
Output: -
No. of char with space
12
#Number of space
print('No. of space')
print( s1.count(' ') )
Output: -
No. of space
1
Output: -
No. of char without space
11
#First Name
print(name[:name.find(' ')])
Output: -
Mehul
#Last Name
print(name[name.find(' ')+1:])
Output: -
Chawla
#Print number of vowels
print(s1.count('a')+s1.count('e')+s1.count('i')+s1.count('o')+s1.count('u'))
Output: -
3
CONCLUSION:
The given experiment to count the number of Characters in a given string and hence to
display the characters of string in reverse order has been performed successfully.
Evaluation table:
TOTAL MARKS
CRITERIA COMMENTS
MARKS OBTAINED
Concept (A) 2
Implementation (B) 2
Performance (C) 2
TOTAL 6
EXPERIMENT 3
Aim : To write a program to find the Simple Interest for input by user for P,R,T
Program :
#input P,R,T
P=int(input('enter the principle amount='))
R=int(input('enter the rate='))
t=int(input('Enter the time in years='))
Output:-
enter the principle amount=2000
enter the rate=30
Enter the time in years=4
Output:-
Simple interest 2400.0
4. Single Line For-Loop to generate list creating S.I. for given rates
rates=[2.5,4,5,6.5]
for R in rates:
SI=(P*R*t)/100
print('simple interest for different rates: ',R,'=',SI)
SI = [(P*R*t)/100 for rate in rates]
print(SI)
Output:-
simple interest for different rates: 2.5 = 200.0
simple interest for different rates: 4 = 320.0
simple interest for different rates: 5 = 400.0
simple interest for different rates: 6.5 = 520.0
[520.0, 520.0, 520.0, 520.0]
Conclusion : We have successfully learned why and how to use range() functions
and have implemented 4 programs on Simple Interest
Evaluation table:
TOTAL MARKS
CRITERIA COMMENTS
MARKS OBTAINED
Concept (A) 2
Implementation (B) 2
Performance (C) 2
TOTAL 6