Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Submitted to :- Submitted by :-

Mr. Manohar Singh Akshay Kumar


(Assistant Professor) Course ;- B.Sc (H) Electronics (1st year)
Roll No :- 6302
Subject :- PFP (ELDSC - 1)
Session :- 2022-23
INDEX
Sr.No Date Program Teacher’s
Remarks
1. 5/12/2022 Write a python menu driven program to calculate area of
circle, rectangle, square using if-elif-else.
2. 5/12/2022 Write a python program to print Fibonacci series up to a
certain limit (use 'while').
3. 12/12/2022 Write a python program to print the Pascal triangle.

4. 19/12/2022 Write a python program to find HCF (GCD) of two


numbers.
5. 19/12/2022 Write a python program to find LCM of two numbers.

6. 26/12/2022 Write Python programs to illustrate the various functions


of the "Math" module, "Statistics" module in Python.
7. 26/12/2022 Write a Python program to count number of vowels
using sets in given string.
8. 2/1/2023 Write a Python program to Remove all duplicates from a
given string in Python
9. 2/1/2023 Write a Python program to count positive and negative
numbers in a list
10. 9/1/2023 Write a Python program to find sum of elements in list

11. 16/1/2023 Write a python program to read a list of 'n' integers


(positive and negative) and create two new lists one
having all positive numbers and the other having all
negative numbers from the given list. Print all three lists.
12. 16/1/2023 Write a python program to create a list of tuples from
given list having number and its cube in each tuple
13. 23/1/2023 Create a Python program to create a dictionary which
has record of a student information: Admission number,
Roll Number, Name and Marks. Display information on
the basis of Admission number
14. 23/1/2023 Write a python program which contains user defined
functions as a 'module' to calculate area, perimeter or
surface area , volume for various shapes like square,
cube, circle, cylinder. The user defined functions should
accept the values for calculation as parameters and
calculated values should be returned. Import the module
and use appropriate functions.
15. 23/1/2023 Create a menu driven Python program using user defined
functions to implement a calculator to perform
(a) Basic arithmetic operations
(b) logl O(x), sin(x) , cos(x)
PROGRAM :- 1
Program :-Write a python menu driven program to calculate area of circle, rectangle,
square using if-elif-else.
Platform :- IDLE (Python 3.11 64-bit)
Code :-
import math
from math import pi
x=str(input("Name of polygon: "))
if x=="Circle":
y=int(input("Enter radius of circle: "))
area=2*pi*y*y
print("Area of circle is" , area)

elif x=="Square":
y=int(input("Enter side of square: "))
area=y*y
print("Area of square is",area)

elif x=="Rectangle":
y = int(input("Enter length of rectangle: "))
z = int(input("Enter breadth of rectangle: "))
area=y*z
print("Area of rectangle is", area)
Input :-
Name of polygon: Square
Enter side of square: 34
Output :-
Area of square is 1156
Discussion :-This program will find the area of a circle, rectangle or square based on the
input given by user under if and elif statement and then will find the area respectively under
the conditional statements.
Conclusion :- We have successfully calculated the area of square of side 34 unit as 1156
unit2.
PROGRAM :- 2
Program :- Write a python program to print Fibonacci series up to a certain limit (use
'while').
Platform :- IDLE (Python 3.11 64-bit)
Code :-
# Program to display the Fibonacci series up to n-th term
terms = int(input("How many terms:- "))
# first two terms
x1 = 0
x2 = 1
y=0
# check if the number of terms is valid
if terms <= 0:
print("Please enter a positive integer")
# if there is only one term, return x1
elif terms == 1:
print("Fibonacci sequence upto",terms,":",x1)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while y < terms:
print(x1)
nth = x1 + x2
# update values
x1 = x2
x2 = nth
y += 1
Input :-
How many terms:- 10
Output :-
Fibonacci sequence:
0 1 1 2 3 5 8 13 21 34
Discussion :-
The Fibonacci sequence is a set of integers that starts with a zero, followed by a one, then
by another one, and then by a series of steadily increasing numbers. The sequence follows
the rule that each number is equal to the sum of the preceding two numbers.
Conclusion :- By giving the input of 10 terms we get the respective Fibonacci series as
per the code.
PROGRAM :- 3
Program:- Write a python program to print the Pascal triangle.
Platform :-IDLE (Python 3.11 64-bit)
Code :-
n = int(input("Enter row number : "))
list1=[]
for i in range(n):
temp_list=[]
for j in range(i+1):
if j==0 or j==i:
temp_list.append(1)
else:
temp_list.append(list1[i-1][j-1] + list1[i-1][j])
list1.append(temp_list)

for i in range(n):
for j in range(n-i-1):
print(format(" ","<3"), end="")
for j in range(i+1):
print(format(list1[i][j],"<6") , end="")
print()

Input :-
Enter row number : 7
Output :-
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
Discussion :- Pascal's triangle is the triangular array of numbers that begins with 1 on
the top and with 1's running down the two sides of a triangle. Each new number lies
between two numbers and below them, and its value is the sum of the two numbers above
it.
Conclusion :-The above code gave the pascal triangle as per the user input of seven
rows.
PROGRAM :- 4
Program:- Write a python program to find HCF (GCD) of two numbers.
Platform :-IDLE (Python 3.11 64-bit)
Code :-
x = int(input("Enter first number : "))
y = int(input("Enter second number : "))
if x>y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if (y%i == 0) and (x%i==0):
hcf = i
print("HCF of",x,"and",y,"is",hcf)
Input :-
Enter first number : 15
Enter second number : 25
Output :-
HCF of 15 and 25 is 5
Discussion :-The greatest common divisor of two or more numbers, which are not all
zero, is the largest commonfactor that divides each of the number, exactly. It is also known
as highest common factor. For e.g. the HCF of 6 and 8 is 2 , since both numbers are
completely divided by 2.
Conclusion :-Using the above program we successfully calculated the HCF of 15 and 25.
PROGRAM :- 5
Program :- Write a python program to find LCM of two numbers.
Platform :-IDLE (Python 3.11 64-bit)
Code :-
x = int(input("Enter first number : "))
y = int(input("Enter second number : "))
if x>y:
greater = x
else:
greater = y

value=greater

while(True):
if(greater % x == 0) and (greater % y == 0):
print("LCM of",x,"and",y,"is",greater)
break
else:
greater=greater+value
Input :-
Enter first number : 23
Enter second number : 12
Output :-
LCM of 23 and 12 is 276
Discussion :-LCM stands for least common multiple. The least common multiple of two
or more numbers is the smallest number that is a common multiple of all of them. For e.g.
the lcm of 3, 4, 5 is 60.
Conclusion :-As per the user input of numbers 23 and 12 the program gave the LCM
276.
PROGRAM :- 6
Program :- Write Python programs to illustrate the various functions of the "Math"
module, "Statistics" module in Python.
Platform :-IDLE (Python 3.11 64-bit)
Code :-
a = min(5, 10, 25)
b = max(5, 10, 25)
print(a)
print(b)

c = abs(-7.25)
print(c)

d = pow(4, 3)
print(d)

import math
e = math.sqrt(64)
print(e)

f = math.ceil(1.4)
g = math.floor(1.4)
print(f)
print(g)

h = math.pi
print(h)
Output :-
5
25
7.25
64
8.0
2
1
3.141592653589793
Code :-
import statistics
print(statistics.mean([1, 3, 5, 7, 9, 11, 13]))
print(statistics.median([1, 3, 5, 7, 9, 11]))
print(statistics.mode([1, 1, -3, 3, 7, -9]))
print(statistics.stdev([1, 3, 5, 7, 9, 11]))
Output :-
7
6.0
1
3.7416573867739413
Discussion :-math is a built-in module in the Python 3 standard library that provides
standard mathematical constants and functions. We can use the math module to perform
various mathematical calculations, such as numeric, trigonometric, logarithmic, and
exponential calculations.
statistics module provides functions for calculating mathematical statistics of numeric (Real -
valued) data. There are various functions in statistics module like mean, median, mode, etc.
Conclusion :-The above codes gave the output of some functions of math and statistics
modules.
PROGRAM :- 7
Program :- Write a Python program to count number of vowels using sets in given string.
Platform :-IDLE (Python 3.11 64-bit)
Code :-
text = str(input("Enter text you want to count vowels in: "))
thisset = {"a","e","i","o","u","A","E","I","O","U"}
count = 0
for x in text:
if x in thisset:
count +=1

print("Number of vowels:",count)
Input :-
Enter text you want to count vowels in: This is my seventh python program.
Output :-
Number of vowels: 7
Discussion :-
1. The code will take input as a string from user in text variable.
2. A set, thisset is defined which contains the vowels in lower form and capitalised form.
3. Another variable named count is also defined which will store the number of vowels
present in a given string.
4. The for loop will traverse through the given string under the conditional statement to
check for vowels.
5. The output will be stored in count variable and print the number of vowels.
Conclusion :- As per the user input of a string, the code gave the number of vowels
present in the string.
PROGRAM :- 8
Program:- Write a Python program to Remove all duplicates from a given string in Python
Platform :-IDLE (Python 3.11 64-bit)
Code :-
x = str(input("Enter a string : "))
i=0
x1 = ""
for n in x:
if x.index(n) == i:
x1 += n
i +=1
print("String after removing duplicate value is ",x1)
Input :-
Enter a string : aaabbb cccddd eeefff ggghhh
Output :-
String after removing duplicate value is ab cdefgh
Discussion :-
1. The variable x will take input from user in string form.
2. The i variable will act as a reference for duplicate strings and x1 will store the strings
after duplicacy is removed.
3. The new sting without duplicacy is printed.
Conclusion :- The code has removed duplicate values from the user input.
PROGRAM :- 9
Program :- Write a Python program to count positive and negative numbers in a list
Platform :-IDLE (Python 3.11 64-bit)
Code :-
a=0
b=0
thislist = []
mylist = []

x = int(input("Enter length of list: "))


for i in range(x):
y = int(input("Enter number : "))
thislist.append(y)
print(thislist)
for j in thislist:
if j<=0:
a +=1
elif j>=0:
b +=1
print("Positive number count in the list: ", b)
print("Negative number count in the list: ", a)
Input :-
Enter length of list: 7
Enter number : 3
Enter number : 3.5
Enter number : 12
Enter number : -2.3
Enter number : -4.1
Enter number : 3
Enter number : -2.2
Output :-
[3.0, 3.5, 12.0, -2.3, -4.1, 3.0, -2.2]
Positive numbers in the list: 4
Negative numbers in the list: 3
Discussion :-
1. The code will take input from user and store in form of a list in thislist variable.
2. The for loop will traverse through each value in the list and if and elif conditions will
check for positive and negative numbers.
3. The positive and negative count will be stored in b and a variable respectively.
4. The result will be printed.
Conclusion :- The code displayed the count of positive and negative numbers in the list
given as input.
PROGRAM :- 10
Program :- Write a Python program to find sum of elements in list
Platform :-IDLE (Python 3.11 64-bit)
Code :-
import math
x = int(input("How many numbers : "))
thislist = []
for i in range(x):
global y
y = int(input("Enter nummber : "))
thislist.append(y)
print(thislist)
print("Sum of the given numbers is ", math.fsum(thislist))
Input :-
How many numbers : 6
Enter number : 13
Enter number : 22
Enter number : 45
Enter number : 63
Enter number : 11
Enter number : 5
Output :-
List is [13, 22, 45, 63, 11, 5]
Sum of the given numbers is 159.0

Discussion :-
1. The code will take input from user and store in form of a list in thislist variable.
2. The fsum function of the math module calculates the sum of the elements present in
the list.
3. The sum is printed.
Conclusion :-The code gave the required sum of the list given as input.
PROGRAM :- 11
Program :- Write a python program to read a list of 'n' integers (positive and negative) and
create two new lists one having all positive numbers and the other having all negative
numbers from the given list. Print all three lists.

Platform :-IDLE (Python 3.11 64-bit)


Code :-
thislist = []
mylist1 = []
mylist2 = []
x = int(input("Enter length of list: "))
for i in range(x):
y = int(input("Enter integer : "))
thislist.append(y)
print(“Given list is :-”,thislist)
for j in thislist:
if j>0:
mylist1.append(j)
elif j<0:
mylist2.append(j)
print("List containing positive integers :",mylist1)
print("List containing negative integers :",mylist2)
Input :-
Enter length of list: 5
Enter integer : 1
Enter integer : 2
Enter integer : -4
Enter integer : 5
Enter integer : -7
Output :-
Given list is :- [1, 2, -4, 5, -7]
List containing positive integers : [1, 2, 5]
List containing negative integers : [-4, -7]
Discussion :-This code will take input from user in form of a list and then for loop will
traverse through each item in the list under conditional statements and then classify them in
two lists each containing negative and positive integers respectively.
Conclusion :- The code successfully gave the negative and positive list based on the
user input.
PROGRAM :- 12
Program :-Write a python program to create a list of tuples from given list having number
and its cube in each tuple
Platform :-IDLE (Python 3.11 64-bit)
Code :-
x = int(input("Enter terms :- "))
thislist = []
list1 = []
list2 = []
for i in range(x):
y = int(input("Enter number : "))
thislist.append(y)
z = y**3
list1.append(z)
list2 = thislist + list1
print("Given list is ",thislist)
print("New list is ", list2)
Input :-
Enter terms :- 4
Enter number : 1
Enter number : 2
Enter number : 3
Enter number : 4
Output :-
Given list is [1, 2, 3, 4]
New list is [1, 2, 3, 4, 1, 8, 27, 64]
Discussion :-The code will take input from user and store in form of a list and the find the
cube of individul item in list and will display the list containing numbers and their cubes.
Conclusion :- The code gave the list containing numbers 1,2,3,4 and their cubes.
PROGRAM :- 13
Program :-Create a Python program to create a dictionary which has record of a student
information: Admission number, Roll Number, Name and Marks. Display information on the
basis of Admission number
Platform :-IDLE (Python 3.11 64-bit)
Code :-
student1 = {
"Admission No.": "101",
"Roll No.": "2",
"Name": "Akshay Kumar",
"Marks": "92.4"
}
x = int(input("Enter admission no. : "))
if x == 101:
print(student1)
else:
print("Please enter 101")
Input :-
Enter admission no. : 101
Output :-
{'Admission No.': '101', 'Roll No.': '2', 'Name': 'Akshay Kumar', 'Marks': '92.4'}

Discussion :-The above code will take admission number as input from user and then
display the information of that student.

Conclusion :- The code gave the information of a student of admission number 101.
PROGRAM :- 14
Program :-Write a python program which contains user defined functions as a 'module' to
calculate area, perimeter or surface area , volume for various shapes like square, cube,
circle, cylinder. The user defined functions should accept the values for calculation as
parameters and calculated values should be returned. Import the module and use
appropriate functions.
Platform :-IDLE (Python 3.11 64-bit)
Code :-
print("Square: 1")
print("Cube : 2")
print("Circle : 3")
print("Cylinder : 4")
x = int(input("Enter your choice : "))
if x == 1:
def square(a):
print("Area of square is :",a*a)
print("Perimeter of square is :",4*a)
return
a = int(input("Enter side of square : "))
square(a)
elif x == 2:
def cube(a):
print("Surface area of cube is :",6*a*a)
print("Volume of cube is :",a*a*a)
return
a = int(input("Enter side of cube : "))
cube(a)
elif x == 3:
def circle(r):
print("Perimeter of circle is :",2*3.14*r)
print("Area of circle is :",3.14*r*r)
return
r = int(input("Enter radius of circle : "))
circle(r)
elif x == 4:
def cylinder(r,h):
print("Surface area of cylinder is :",2*3.14*r*r + 2*3.14*r*h)
print("Volume of cylinder is :",3.14*r*r*h)
return
r = int(input("Enter radius of cyliner : "))
h = int(input("Enter height of cyliner : "))
cylinder(r,h)
Input :-
Square: 1
Cube : 2
Circle : 3
Cylinder : 4
Enter your choice : 4
Enter radius of cyliner : 2
Enter height of cyliner : 5
Output :-
Surface area of cylinder is : 87.92
Volume of cylinder is : 62.800000000000004
Discussion :- The program will take input from user as per the requirement and will give
the required calculation based on input.

Conclusion :-The program gave the surface area and volume of a cylinder of radius 2 unit
and height 5 unit.
PROGRAM :- 15
Program :-Create a menu driven Python program using user defined functions to implement a
calculator to perform
(a) Basic arithmetic operations
(b) log10(x), sin(x) , cos(x)

Platform :-IDLE (Python 3.11 64-bit)


Code :-
(a)
print("Add : 1")
print("Subtract : 2")
print("Multiply : 3")
print("Divide : 4")
x = int(input("Your choice : "))
if x == 1:
def plus(num1,num2):
print(num1+num2)
return
num1 = int(input("Enter 1st number :"))
num2 = int(input("Enter 2nd number :"))
plus(num1,num2)
elif x == 2:
def minus(num1,num2):
print(num1-num2)
return
num1 = int(input("Enter 1st number :"))
num2 = int(input("Enter 2nd number :"))
minus(num1,num2)
elif x == 3:
def multiply(num1,num2):
print(num1*num2)
return
num1 = int(input("Enter 1st number :"))
num2 = int(input("Enter 2nd number :"))
multiply(num1,num2)
elif x == 4:
def divide(num1,num2):
print(num1/num2)
return
num1 = int(input("Enter 1st number :"))
num2 = int(input("Enter 2nd number :"))
divide(num1,num2)
Input :-
Add : 1
Subtract : 2
Multiply : 3
Divide : 4
Your choice : 4
Enter 1st number :12
Enter 2nd number :24
Output :-
0.5
(b)
import math
print("log10(x) : 1")
print("sin(x) : 2")
print("cos (x) : 3")
x = int(input("Enter your choice : "))
if x == 1:
def myfunc1(num):
print(math.log10(num))
return
num = int(input("Enter number : "))
myfunc1(num)
elif x == 2:
def myfunc2(num):
print(math.sin(num))
return
num = int(input("Enter number : "))
myfunc2(num)
elif x == 3:
def myfunc3(num):
print(math.cos(num))
return
num = int(input("Enter number : "))
myfunc3(num)
Input :-
log10(x) : 1
sin(x) : 2
cos (x) : 3
Enter your choice : 2
Enter number : 30
Output :-
-0.9880316240928618
Discussion :-The above two programs will find the arithmetic operations and various
function based on user input.
Conclusion :- The first program gave the quotient based on input.
The second program gave the sin of the input given in radians.

You might also like