ShriyaManuja Practical File
ShriyaManuja Practical File
ShriyaManuja Practical File
Batch- 2023-25
Section- A (North Campus)
Roll No.- 23236761049
College- Department of Operational Research
Python Practical File
1
Table of Contents
2
26 Write a program in python to plot a pie chart on consumption of 39
water in daily life.
27 WAP to find whether a year is leap year or not 40
3
Practical 1
'''
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical-1b
Practical-1c
Title- WAP to take a review from user and display the character count of the
review
Please enter the sentence: Happiness can be found, even in the darkest of times,
if one only remembers to turn on the light.
97
4
Practical 2
'''
Name: Shriya Manuja
Section: A
Batch :2023-25
Practical 2: Write a menu driven program to enter two numbers and print the arithmetic operations
'''
'''
OUTPUT CASE 1
Enter First Number: 1
Enter Second Number: 2
Enter the arithmetic operation you want to perform (+,-,*,/,//,%,**): +
Sum of the numbers you entered is 3.0
OUTPUT CASE 2
Enter First Number: 1
Enter Second Number: 2
Enter the arithmetic operation you want to perform (+,-,*,/,//,%,**): -
Difference of the numbers you entered is -1
OUTPUT CASE 3
Enter First Number: 1
5
Enter Second Number: 2
Enter the arithmetic operation you want to perform (+,-,*,/,//,%,**): *
Product of the numbers you entered is 2.0
OUTPUT CASE 4
Enter First Number: 1
Enter Second Number: 2
Enter the arithmetic operation you want to perform (+,-,*,/,//,%,**): /
Division of the numbers you entered is 0.5
OUTPUT CASE 5
Enter First Number: 2.5
Enter Second Number: 1
Enter the arithmetic operation you want to perform (+,-,*,/,//,%,**): //
Floor Division of the numbers you entered is 2.0
OUTPUT CASE 6
Enter First Number: 10
Enter Second Number: 3
Enter the arithmetic operation you want to perform (+,-,*,/,//,%,**): %
Remainder after division of the numbers you entered is 1.0
OUTPUT CASE 7
Enter First Number: 5
Enter Second Number: 2
Enter the arithmetic operation you want to perform (+,-,*,/,//,%,**): **
5.0 raised to the power 2.0 is 25.0
OUTPUT CASE 8
Enter First Number: 12
Enter Second Number: 43
Enter the arithmetic operation you want to perform (+,-,*,/,//,%,**): ^
Enter a valid operator!
‘’’
6
Practical 3
'''
Name: Shriya Manuja
Section: A
Batch: 2023-25
Practical 3: To compute roots of a quadratic equation
'''
Title- WAP to compute roots of a quadratic equation
import math
import cmath
a= input("Please enter a: ")
b= input("Please enter b: ")
c= input("Please enter c: ")
print("Your quadratic equation is (" + a+")x^2" + " + (" + b + ")x"+ " + ("
+c+")")
D = int(b)**2- 4* int(a)*int(c)
print("The discriminant is " + str(D))
if D > 0:
root_1 = (-int(b)+math.sqrt(D))/(2*int(a))
root_2 = (-int(b)-math.sqrt(D))/(2*int(a))
print("The roots are real and distinct " + str(root_1) +", "+ str(root_2))
elif D == 0:
root_3 = (-int(b)+sqrt(D))/(2*int(a))
print("The roots are real and equal " + str(root_3))
elif D <0:
root_4 = (-int(b)+cmath.sqrt(D))/(2*int(a))
root_5 = (-int(b)-cmath.sqrt(D))/(2*int(a))
print("The roots are complex and distinct " + str(root_4) +", "+
str(root_5))
Please enter a: 2
Please enter b: 4
Please enter c: 1
Your quadratic equation is (2)x^2 + (4)x + (1)
The discriminant is 8
The roots are real and distinct -0.2928932188134524, -1.7071067811865475
7
Practical 4
'''
Name: Shriya Manuja
Section: A
Batch: 2023-25
Practical 4: Write a menu driven program to reverse the digits and sum of the given number
'''
print("1. for reverse" )
print("2. For sum" )
choice=int(input("enter choice "))
n=int(input("Enter number "))
if choice==1:
rem=0
sum=0
temp=n
while(temp>0):
a=temp%10
temp=temp//10
rem=rem*10+a
print("Reverse",rem)
else:
sum=0
temp=n
while(temp>0):
a=temp%10
temp=temp//10
sum=sum+a
print("sum",sum)
'''
Output 1
1. for reverse
2. For sum
enter choice 1
Enter number 248
sum 14
Output 2
1. for reverse
2. For sum
enter choice 1
Enter number 378
Reverse 873
'''
8
Practical 5
'''
Name: Shriya Manuja
Section :A
Batch : 2023-25
Practical 5: Write a menu driven program to enter a number whether number is odd or even or
prime
'''
'''
OUTPUT 1
Enter a number 14
1. for odd even
2. for prime
Enter your choice 2
not prime
OUTPUT 2
Enter a number 17
1. for odd even
2. for prime
Enter your choice 1
odd
'''
9
Practical 6
'''
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 6: WAP to find maximum out of entered 3 numbers
'''
10
Practical 7
'''
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 7: Write a program to display ASCII code of a character and vice versa.
'''
def display_ascii(user_input):
user_input = str(user_input)
for i in user_input:
print(f"ASCII code for {i} is {ord(i)}")
def decode_ascii(ascii_code):
print(f"The character value of {ascii_code} ASCII value is:
{chr(ascii_code)}")
‘’’
OUTPUT
Enter your character for ASCII value : Hello
ASCII code for o is 111
ASCII code for e is 101
ASCII code for H is 72
ASCII code for l is 108
Enter your ASCII value for character : 101
The character value of 72 ASCII value is: e
‘’’
11
Practical 8
'''
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 8: Write a program to check if the entered number is Armstrong or not.
'''
def armStrongNumber(user_input):
user_input = str(user_input)
expo = len(user_input)
sum=0
for i in user_input:
sum+=(int(i)**expo)
if(sum == int(user_input)):
print("Given Number is ArmStrong Number")
else:
print("Given Number is not Armstrong Number")
'''
OUTPUT
Enter your number : 346
Given Number is not ArmStrong Number
12
Practical 9
'''
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 9: Write a program in python language to find factorial of the entered number using
recursion.
‘’’
def factorial(n):
if (n==1 or n==0):
return 1
else:
4 ! = 24
'''
13
Practical 10
‘’’
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 10: Write a program in python language to enter the number of terms and to print the
Fibonacci series.
‘’’
def fibonacci(n):
if n == 1:
return 0
if n == 2:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
for i in range(1,l+1):
print(fibonacci(i), end = " ")
‘’’
OUTPUT
Input the number of fibonacci terms : 7
0 1 1 2 3 5 8
'''
14
Practical 11
'''
Name : Shriya Manuja
Section A
Batch: 2023-25
Practical 11: Write a Program to enter the numbers and to print greatest number using loop.
'''
lar_num= int(input ("enter a number initially : "))
check_num= input ("enter a number to check wether it is largest or
not : ")
while check_num != "Done" :
if lar_num > int(check_num):
print(f"The largest number is {lar_num}")
else :
lar_num= int(check_num)
print(f"The largest number is {lar_num} ")
check_num= input ("enter a number to check wether it is largest or
not : ")
'''
OUTPUT
enter a number initially : 5
enter a number to check wether it is largest or not : 2
The largest number is 5
enter a number to check wether it is largest or not : 7
The largest number is 7
enter a number to check wether it is largest or not : 6
The largest number is 7
enter a number to check wether it is largest or not : Done
'''
15
Practical 12
'''
Name : Shriya Manuja
Section A
Batch: 2023-25
Practical 12: Write a Program to enter the string and to check if it’s palindrome or not using loop.
'''
rev_str = ""
for i in string:
rev_str = i + rev_str
if(string == rev_str):
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
'''
OUTPUT CASE 1
Enter string : string
Reversed string : gnirts
The string is not a palindrome.
OUTPUT CASE 2
Enter string : madam
Reversed string : madam
The string is a palindrome.
'''
16
Practical 13
'''
Name : Shriya Manuja
Section A
Batch: 2023-25
Practical 13: Write a Program to enter the 5 subjects’ numbers and print the grades A/B/C/D/E.
'''
def grade_alot(s):
if s <0 or s>100:
print("Wrong Input")
elif s>90:
print("Grade A")
elif s>80:
print("Grade B")
elif s>70:
print("Grade C")
elif s>60:
print("Grade D")
else:
print("Grade E")
'''
OUTPUT
Enter English marks: 65
Enter Hindi marks: 72
Enter Mathematics marks: 85
Enter Physics marks: 90
Enter Chemistry marks: 73
The marks in English is 65 and thus grade is:
Grade D
17
The marks in Hindi is 72 and thus grade is:
Grade C
The marks in Mathematics is 85 and thus grade is:
Grade B
The marks in Physics is 92 and thus grade is:
Grade A
The marks in Chemistry is 73 and thus grade is :
Grade C
The Averages marks is 75.0 and thus average grade is:
Grade C
'''
18
Practical 14
'''
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 14: Write a program in python language to display the given pattern
'''
n=int(input("Enter rows needed "))
for i in range(n):
for j in range(n-i-1):
print(" ", end=" ")
for j in range(i,-1,-1):
print(n-j,end=" ")
print()
'''
OUTPUT
Enter rows needed 5
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
19
Practical 15
'''
Name : Shriya Manuja
Section A
Batch: 2023-25
Practical 15: Write a python function sin(x,n) to calculate the value of sin(x) using its Taylor series
expansion up to n terms.
'''
x=int(input("Enter the degree: "))
n=int(input("Enter the number of terms: "))
def sin():
r=x*22/7*180
result=0
numerator = r
denominator= 1
for i in range (1, n+1):
single_term= numerator/denominator
result+= single_term
numerator = -numerator*r*r
denominator= denominator*(2*i)*(2*i+1)
return result
def main():
result= sin()
print(f"The value of sin({x}) is {result} ")
main()
'''
OUTPUT
Enter the degree: 0
Enter the number of terms: 10
The value of sin(0) is 0.0
'''
20
Practical 16
'''
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 16: WAP to determine EOQ using various inventory models.
'''
import math
def eoq():
print("EOQ Model Initiated...")
y=float(input("Enter Annual Demand: "))
a=float(input("Enter Ordering Cost per order: "))
ic=(input("For Inventory Carrying/Holding Cost\nDo you want to
enter Cost or Percentage?
")).lower()
if ic=='cost':
h=float(input("Enter Inventory Carrying/Holding Cost per
year: "))
elif ic=='percentage':
c=float(input("Enter Unit Cost of the item: "))
i=float(input("Enter Percentage of Unit Cost, taken into
consideration for
Carrying/Holding Cost: "))
h=i*c/100
else:
print("Invalid Choice!")
eoq=math.sqrt((2*y*a)/h)
print(f"The Economic Order Quantity using the EOQ Model is {eoq}
units.")
def epq():
print("EPQ ModelInitiated...")
y=float(input("Enter Annual Demand: "))
s=float(input("Enter Annual Production: "))
assert y<s, "Production shall be more than the Demand."
a=float(input("Enter Setup Cost per order: "))
ic=(input("For Inventory Carrying/Holding Cost\nDo you want to
enter Cost or Percentage?
")).lower()
if ic=='cost':
h=float(input("Enter Inventory Carrying/Holding Cost per
year: "))
elif ic=='percentage':
c=float(input("Enter Unit Production Cost of the item: "))
i=float(input("Enter Percentage of Unit Cost, taken into
consideration for
Carrying/Holding Cost: "))
h=i*c/100
else:
print("Invalid Choice!")
factor=s/(s-y)
epq=math.sqrt((2*y*a*factor)/h)
print(f"The Economic Order Quantity using the EPQ Model is {epq}
units.")
def backorders():
print("Backorders Model With Planned Shortages EOQ
Initiated. .. ")
y=float(input("Enter Annual Demand: "))
a=float(input("Enter Ordering/Setup Cost per order: "))
pi=float(input("Enter Backorder Cost per unit per year: "))
ic=(input("For Inventory Carrying/Holding Cost\nDo you want to
enter Cost or Percentage?
")).lower()
if ic=='cost':
h=float(input("Enter Inventory Carrying/Holding Cost per
year: "))
elif ic=='percentage':
c=float(input("Enter Unit Cost of the item: "))
i=float(input("Enter Percentage of Unit Cost, taken into
consideration for
Carrying/Holding Cost: "))
h=i*c/100
else:
22
print("Invalid Choice!")
factor=(h+pi)/pi
q=math.sqrt((2*y*a*factor)/h)
s=(h/(h+pi))*q
print(f"The Economic Order Quantity using the EOQ with
Backorders Model (planned
shortages) is {q}units.")
def finsupply():
print("EOQ with Finite Supply Model Initiated...")
y=float(input("Enter Annual Demand: "))
a=float(input("Enter Ordering/Setup Cost per order: "))
s=float(input("Enter Annual Supply/Production: "))
ic=(input("For Inventory Carrying/Holding Cost\nDo you want to
enter Cost or Percentage? ")).lower()
if ic=='cost':
h=float(input("Enter Inventory Carrying/Holding Cost per
year: "))
elif ic=='percentage':
c=float(input("Enter Unit Cost of the item: "))
i=float(input("Enter Percentage of Unit Cost, taken into
consideration for
Carrying/Holding Cost: "))
h=i*c/100
else:
print("Invalid Choice!")
factor=math.sqrt(s/(s-y))
q=factor*math.sqrt((2*y*a)/h)
print(f"The Economic Order Quantity using the EOQ with Finite
Supply Model is {q} units.")
def main():
print("Hello \n KIndly enter the Model No. of the model you want
to use")
print("MODEL 1: EOQ\nMODEL 2: EPQ\nMODEL 3: EOQ with Backorders
(planned shortages\nMODEL
4: EOQ with Finite Supply)")
23
choice=input("Enter your choice: ")
if choice=='1':
eoq()
if choice=='2':
epq()
if choice=='3':
backorders()
if choice=='4':
finsupply()
'''
OUTPUT CASE 1
Hello kindly enter the Model No. of the model you want to use
MODEL 1: EOQ
MODEL 2: EPQ
MODEL 3: EOQ with Backorders (planned shortages
MODEL 4: EOQ with Finite Supply)
Enter your choice: 1
EOQ Model Initiated...
Enter Annual Demand: 1200
Enter Ordering Cost per order: 200
For Inventory Carrying/Holding Cost
Do you want to enter Cost or Percentage? Cost
Enter Inventory Carrying/Holding Cost per year: 1
The Economic Order Quantity using the EOQ Model is 692.8203230275509 units.
OUTPUT CASE 2
Hello kindly enter the Model No. of the model you want to use
MODEL 1: EOQ
MODEL 2: EPQ
MODEL 3: EOQ with Backorders (planned shortages
MODEL 4: EOQ with Finite Supply)
Enter your choice: 2
EPQ Model Initiated...
Enter Annual Demand: 1200
24
Enter Annual Production: 1400
Enter Setup Cost per order: 200
For Inventory Carrying/Holding Cost
Do you want to enter Cost or Percentage? Cost
Enter Inventory Carrying/Holding Cost per year: 2
The Economic Order Quantity using the EPQ Model is 1296.148139681572 units.
OUTPUT CASE 3
Hello kindly enter the Model No. of the model you want to use
MODEL 1: EOQ
MODEL 2: EPQ
MODEL 3: EOQ with Backorders (planned shortages
MODEL 4: EOQ with Finite Supply)
Enter your choice: 3
Backorders Model with Planned Shortages EOQ Initiated....
Enter Annual Demand: 1200
Enter Ordering/Setup Cost per order: 200
Enter Backorder Cost per unit per year: 30
For Inventory Carrying/Holding Cost
Do you want to enter Cost or Percentage? Cost
Enter Inventory Carrying/Holding Cost per year: 7
The Economic Order Quantity using the EOQ with Backorders Model (planned shortages) is
290.81167199998794units.
The Maximum number of Backorders can be 55.01842443243015 units.
OUTPUT CASE 4
Hello kindly enter the Model No. of the model you want to use
MODEL 1: EOQ
MODEL 2: EPQ
MODEL 3: EOQ with Backorders (planned shortages
MODEL 4: EOQ with Finite Supply)
Enter your choice: 4
EOQ with Finite Supply Model Initiated...
Enter Annual Demand: 1200
Enter Ordering/Setup Cost per order: 200
Enter Annual Supply/Production: 1400
For Inventory Carrying/Holding Cost
25
Do you want to enter Cost or Percentage? Percentage
Enter Unit Cost of the item: 15
Enter Percentage of Unit Cost, taken into consideration for Carrying/Holding Cost: 20
The Economic Order Quantity using the EOQ with Finite Supply Model is 1058.3005244258363
units.'''
26
Practical 17
'''
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 17: Programme to determine different characteristics using various Queuing models.
'''
import math
27
print()
# Example usage:
M_M_1(2, 3)
M_M_c(2, 3, 5)
M_M_1_K(2 ,3, 4)
'''
OUTPUT
M/M/1 Model:
Expected number of customers in the queue (Lq): 1.333333333333333
Expected number of customers in the system (L): 1.9999999999999996
Expected time in the queue (Wq): 0.6666666666666665
Expected time in the system (W): 0.9999999999999998
M/M/c Model:
Expected number of customers in the queue (Lq): 9.995743479235089e-05
Expected number of customers in the system (L): 0.6667666241014589
Expected time in the queue (Wq): 4.9978717396175446e-05
28
Expected time in the system (W): 0.33338331205072946
M/M/1/K Model:
Expected number of customers in the queue (Lq): 0.24170616113744092
Expected number of customers in the system (L): 0.9083728278041076
Expected time in the queue (Wq): 0.12085308056872046
Expected time in the system (W): 0.4541864139020538
'''
29
Practical 18
‘’’
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 18: WAP to implement Inheritance. Create a class Employee inherit two classes Manager
and Clerk from Employee.
'''
class Employee:
self.name = name
self.emp_id = emp_id
self.salary = salary
def display_employee_details(self):
print(f"Salary: {self.salary}")
class Manager(Employee):
self.department = department
def display_manager_details(self):
self.display_employee_details()
print(f"Department: {self.department}")
class Clerk(Employee):
self.shift = shift
def display_clerk_details(self):
30
self.display_employee_details()
print(f"Shift: {self.shift}
manager1.display_manager_details()
print("\n")
clerk1.display_clerk_details()
'''
OUTPUT
Employee Name: John
Employee ID: 1001
Salary: 50000
Department: Sales
31
Practical-19
‘’’
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 19: WAP to fit Poisson Distribution to given data
‘’’
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from scipy.special import factorial
def poisson(k, lamb, scale):
return scale*(lamb**k/factorial(k))*np.exp(-lamb)
np.random.seed(42)
data = np.random.poisson(5,100)
fig, ax = plt.subplots()
ax.hist(data,bins=10,alpha=0.3)
y,x=np.histogram(data,bins=10)
x = x + (x[1]-x[0])/2
x = np.delete(x,-1)
parameters, cov_matrix = curve_fit(poisson, x, y, p0=[2., 2.])
x_new = np.linspace(x[1], x[-1], 50)
ax.plot(x_new, poisson(x_new, *parameters), color='b')
'''
Output
‘’’
32
Practical 20
‘’’
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 20: WAP to implement Linear Regression using Python.
‘’’
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
x = 30 * np.random.random((20, 1))
model = LinearRegression()
model.fit(x, y)
plt.figure(figsize=(4, 3))
ax = plt.axes()
ax.scatter(x, y)
ax.plot(x_new, y_new)
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.show()
'''
Output
‘’’
33
Practical 21
‘’’
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 21: WAP to perform read and write operations in Python with csv files.
‘’’
import pandas as pd
#reading a csv filen
df = pd.read_csv('iris.csv')
print(df)
'''
Output
sepal.length sepal.width petal.length petal.width variety
0 5.1 3.5 1.4 0.2 Setosa
1 4.9 3.0 1.4 0.2 Setosa
2 4.7 3.2 1.3 0.2 Setosa
3 4.6 3.1 1.5 0.2 Setosa
4 5.0 3.6 1.4 0.2 Setosa
.. ... ... ... ... ...
145 6.7 3.0 5.2 2.3 Virginica
146 6.3 2.5 5.0 1.9 Virginica
147 6.5 3.0 5.2 2.0 Virginica
148 6.2 3.4 5.4 2.3 Virginica
149 5.9 3.0 5.1 1.8 Virginica
34
Practical 22
‘’’
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 22: WAP to enter multiple values-based data in multiple columns/rows and show that data
in python using DataFrames and pandas.
‘’’
import pandas as pd
students = [['Jack Ma', 34, 'Sydney', 'Australia'],
['Ritika', 30, 'Delhi', 'India'],
['Vansh', 31, 'Delhi', 'India'],
['Nany', 32, 'Tokyo', 'Japan'],
['May', 16, 'New York', 'US'],
['Michael', 17, 'Las Vegas', 'US']]
print(data_new)
'''
Output
Name Age City Country
0 jackma 34 Sydeny Australia
1 Ritika 30 Delhi India
2 Vansh 31 Delhi India
3 Nany 32 Tokyo Japan
4 May 16 New York US
5 Michael 17 las vegas US
‘’’
35
Practical 23
‘’’
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 23: WAP in python to perform various statistical measures using pandas.
‘’’
import numpy as np
import pandas as pd
mydata = np.random.randn(9).reshape(3,3)
mydata = pd.DataFrame(mydata, columns = ["a","b","c"])
print(mydata)
print(mydata.describe())
'''
Output
a b c
0 0.543080 -0.119660 -0.236676
1 -0.462042 0.921270 -0.394241
2 0.481430 -1.326521 -1.461620
a b c
count 3.000000 3.000000 3.000000
mean 0.187490 -0.174970 -0.697512
std 0.563354 1.124916 0.666410
min -0.462042 -1.326521 -1.461620
25% 0.009694 -0.723090 -0.927930
50% 0.481430 -0.119660 -0.394241
75% 0.512255 0.400805 -0.315458
max 0.543080 0.921270 -0.236676
‘’’
36
Practical 24
‘’’
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 24: WAP to plot a bar chart in python to display the result of a school for five consecutive
years.
‘’’
import numpy as np
import matplotlib.pyplot as plt
‘’’
37
Practical 25
‘’’
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 25: WAP to plot a graph for the function y = x2
‘’’
'''
Output
‘’’
38
Practical 26
'''
Name: Shriya Manuja
Section: A
Batch:2023-25
Practical 26: WAP plot a pie chart on consumption of water in daily life.
'''
import matplotlib.pyplot as plt
water = {'Drinking' : 0.25, 'Washing Clothes/Utensils' : 0.40,
'Bathing' : 0.35}
use = list(water.keys())
val = list(water.values())
plt.pie(val, labels = use, autopct='%1.2f%%')
plt.title("Consumption of Water in Daily Life")
plt.show()
‘’’
Output
‘’’
39
Practical 27
40
Practical-28
41
Practical 29
42
elif L1== "Right":
print("This was the Wrong choice. There is a crocodile. The End.")
else: print("Alas! Maybe next time?")
43
Practical 30
Title- WAP to generate bill from pizza shop depending on user preference from
small,medium, large. Extra topping charge is
separate and extra charge for cheese burst addition.
tot = 0
name= input("May I know your name?")
print("Welcome to Pizzaza " + name + " What would you like to have?")
size = input("Please choose a size Small/Medium/Large: ")
if size == "Small":
tot=tot+100
x_topping = input("Would you like extra topping Yes/No: ")
if x_topping == "Yes":
tot=tot+30
x_cheese = input("Would you like extra cheese Yes/No: ")
if x_cheese == "Yes":
tot=tot+20
print("Your bill is: "+ str(tot))
elif x_cheese == "No":
print("Your bill is:" + str(tot))
elif x_topping == "No":
x_cheese = input("Would you like extra cheese Yes/No: ")
if x_cheese == "Yes":
tot=tot+20
print("Your bill is: "+ str(tot))
elif x_cheese == "No":
print("Your bill is:" + str(tot))
elif size == "Medium":
tot = tot+200
x_topping = input("Would you like extra topping Yes/No: ")
if x_topping == "Yes":
tot=tot+30
x_cheese = input("Would you like extra cheese Yes/No: ")
if x_cheese == "Yes":
tot=tot+20
print("Your bill is: "+ str(tot))
elif x_cheese == "No":
print("Your bill is:" + str(tot))
elif x_topping == "No":
x_cheese = input("Would you like extra cheese Yes/No: ")
if x_cheese == "Yes":
tot=tot+20
print("Your bill is: "+ str(tot))
elif x_cheese == "No":
print("Your bill is:" + str(tot))
elif size == "Large":
tot = tot+500
x_topping = input("Would you like extra topping Yes/No: ")
if x_topping == "Yes":
tot=tot+50
x_cheese = input("Would you like extra cheese Yes/No: ")
44
if x_cheese == "Yes":
tot=tot+40
print("Your bill is: "+ str(tot))
elif x_cheese == "No":
print("Your bill is:" + str(tot))
elif x_topping == "No":
x_cheese = input("Would you like extra cheese Yes/No: ")
if x_cheese == "Yes":
tot=tot+20
print("Your bill is: "+ str(tot))
elif x_cheese == "No":
print("Your bill is:" + str(tot))
45
Practical 31
import random
list=["stone","paper","scissor"]
uc=input("Enter user choice: ")
y=random.choice(list)
print("Computer chose",y)
if uc=="stone":
if y=="stone":
print("Tie")
elif y=="paper":
print("Computer wins")
else:
print("User wins")
elif uc=="paper":
if y=="paper":
print("Tie")
elif y=="scissor":
print("Computer wins")
else:
print("User wins")
else:
if y=="scissor":
print("Tie")
elif y=="stone":
print("Computer wins")
else:
print("User wins")
Output:
1.)
Enter user choice: stone
Computer chose paper
Computer wins
2.)
Enter user choice: scissor
Computer chose stone
Computer wins
3.)
Enter user choice: paper
Computer chose stone
User wins
46
Practical 32
#WAP that inputs the no. of characters for your password,then it asks for the no
of letters,no of numeric figures, no of special characters to be included. Then
the computer will generate a random password(system generated) for the inputs
taken shuffled
# Shuffled #
import string
import random
alpha=int(input("Enter the number of alphabets required for password: "))
num=int(input("Enter the number of numerics required for password: "))
symbol=int(input("Enter the number of special characters required for password:
"))
a=list(string.ascii_uppercase)+list(string.ascii_lowercase)
n=['0','1','2','3','4','5','6','7','8','9']
s=['!','@','#','$','%','&','*','^']
password=""
pass2=''
y=''
for i in range(0,alpha):
password=password+random.choice(a)
for i in range(0,num):
password=password+random.choice(n)
for i in range(0,symbol):
password=password+random.choice(s)
for i in range(0,alpha+num+symbol):
y=y+password[i]
for i in range(0,alpha+num+symbol):
pass2=pass2+random.choice(y)
print("Shuffled password is ",pass2)
Output:
Enter the number of alphabets required for password: 7
Enter the number of numerics required for password: 7
Enter the number of special characters required for password: 4
Shuffled password is *12#10&8g%98Z1&085
47
#########Not shuffled#######
#WAP that inputs the no. of characters for your password,then it asks for the no
of letters,no of numeric figures, no of special characters to be included. Then
the computer will generate a random password(system generated) for the inputs
taken
import string
import random
alpha=int(input("Enter the number of alphabets required for password: "))
num=int(input("Enter the number of numerics required for password: "))
symbol=int(input("Enter the number of special characters required for password:
"))
a=list(string.ascii_uppercase)+list(string.ascii_lowercase)
n=['0','1','2','3','4','5','6','7','8','9']
s=['!','@','#','$','%','&','*','^']
password=""
for i in range(0,alpha):
password=password+random.choice(a)
for i in range(0,num):
password=password+random.choice(n)
for i in range(0,symbol):
password=password+random.choice(s)
print("Your password is",password)
Output:
Enter the number of alphabets required for password: 7
Enter the number of numerics required for password: 7
Enter the number of special characters required for password: 4
Your password is ysPYZa8697451!$^
48