Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Practical Lab File

Introduction to Python
Code: ECE319

Submitted by
Mehul Chawla
A2305120014
5ECE1-X

Submitted to
Dr Rinki Gupta
Associate Professor

Department of Electronics and Communication Engineering


Amity School of Engineering and Technology
Amity University, Noida, Uttar Pradesh
Table of Contents

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.

Write a program to read two


Mandatory integers and find the sum,
1. 1. 27/07/2022 1
Experiment difference, multiplication, and
division.
Write a python program to
count the number of
Mandatory Characters in a given string
2. 2. 03/08/2022 1
Experiment and hence to display the
characters of string in reverse
order.
Write a program to find the
Mandatory Simple Interest for input by user 10/08/2022
3. 3. 1
Experiment for P,R,T

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.

Operator Description Syntax

+ Addition: adds two operands x+y

– Subtraction: subtracts two operands x–y

* Multiplication: multiplies two operands x*y

/ Division (float): divides the first operand by the second x/y

Modulus: returns the remainder when the first operand is divided


% by the second x%y

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

print('%d - %d = %d' %(var1,var2, var1-var2)) #Subtraction

print('%d * %d = %d' %(var1,var2, var1*var2)) #Multiplication

print('%d / %d = %.1f' %(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

#Format3

print('{} + {} = {}' .format(var1,var2, var1+var2)) #Addition


print('{} - {} = {}' .format(var1,var2, var1-var2)) #Subtraction
print('{} * {} = {}' .format(var1,var2, var1*var2)) #Multiplication
print('{} / {} = {}' .format(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
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

print('No. of char with space')


print(len(name))

Output: -
No. of char with space
12

#Number of space

print('No. of space')
print( s1.count(' ') )

Output: -
No. of space
1

#Number of characters without space

print('No. of char without space')


print( len(name)-s1.count(' ') )

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

Description of Syntax : The range() function returns a sequence of numbers,


starting from 0 by default, and increments by 1 (by default), and stops before a
specified number.

Syntax - range(start, stop, step)

Program :

1.Calculate Simple Interest and Display

#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

2.Calculate simple interest and display it

#Calculate SI and display it


SI=((P*R*t)/100)
print('Simple interest', SI)

Output:-
Simple interest 2400.0

3.Evaluate Total Amount at the end of each year

#Evaluation of total amount at the end of each year


for t in range(1,t+1):
SI=(P*R*t)/100
print('Total amount at the end of year',t,'=',P+SI)
Output:-
Total amount at the end of year 1 = 2600.0
Total amount at the end of year 2 = 3200.0
Total amount at the end of year 3 = 3800.0
Total amount at the end of year 4 = 4400.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

You might also like