Pseudocode Practice Python
Pseudocode Practice Python
Write Algorithms of following given python codes using these stated examples
Example: 1
total = 0
Example: 2
INPUT Number
Example: 3
Example: 4
python Code
if number > 0 :
print(“Positive”)
elif number = 0:
print(“Exactly zero”)
else:
print(“Negative”)
Algorithm
IF number > 0
Then
OUTPUT “ Positive ”
Elseif number = 0
Then
OUTPUT “ Exactly Zero ”
ELSE
OUTPUT = “Negative ”
ENDIF
Example: 5
Price = [0,0,0,0,0]
if x == 0 :
print("Zero value ")
if x < 0 :
print("Neg Value ")
eyecolor = 0
eyecolor = input("Enter your eye color :")
if eyecolor == "green":
print("Goblin")
else:
print("you must be a different type of monster")
currency = 0
drink = 0
choice = 0
currency = int(input("Enter 50 Rs Note: "))
if currency == 50:
choice = int(input("Enter your choice of Drink: "))
if choice == 1:
drink = "Coke"
print(drink, " can dropped, Thanks for your
Purchase")
if choice == 2:
drink = "Pepsi"
print(drink, " can dropped, Thanks for your
Purchase")
if choice == 3:
drink = "Fanta"
print(drink, " can dropped, Thanks for your
Purchase")
if choice == 4:
drink = "7up"
print("Pname")
for y in range(0,4):
print(product[y])
pname = [0,0,0]
qty = [0,0,0]
price = [0,0,0]
total = [0,0,0]
for x in range(0,3):
pname[x] = input("enter product name : ")
qty[x] = int(input("enter product qty : "))
price[x] = int(input("enter product price : "))
total[x] = qty[x] * price[x]
print()
print("pname", "\t", "qty", "\t", "price", "\t", "Total")
for y in range(0,3):
print(pname[y],"\t", qty[y],"\t", price[y],"\t", total[y])
speed = 0
tfine = 0
fine = 500
cars = 0
cars = int(input("Enter no of cars : "))
for x in range(0,cars):
print("Car no : ",x+1)
speed = int(input("Enter car speed : "))
if speed > 120 :
print("Challan Issued : ")
for a in range(0,4):
print(nums[a])
names = [“BASHIR”,”WAQAS”,”HAMID”,”NAVID”]
temp = 0
for x in range(0,3):
for y in range(0,3):
if names[x] > names[x + 1]:
temp = names[x]
names[x] = names[x + 1]
names[x + 1] = temp
for a in range(0,4):
print(names[a])
item = 0
found = False
d=0
nums = [23, 67, 90, 87, 45, 22]
item = int(input("Enter number to search : "))
for x in range(0, 6):
if item == nums[x]:
found = True
d=x
if found == True:
print("Data found : ", d)
else:
print("Data not in list : ")
stname = 0
marks = 0
grade = 0
for x in range(0,5):
stname = input("Enter St Name : ")
marks = int(input("Enter student marks :"))
if marks >= 90 and marks <= 100 :
grade = "A*"
elif marks >= 80 and marks <= 89 :
grade = "A"
elif marks >= 70 and marks <= 79 :
grade = "B"
elif marks >= 60 and marks <= 69 :
grade = "C"
elif marks >= 50 and marks <= 59 :
grade = "D"
elif marks >= 40 and marks <= 49 :
grade = "E"
print(stname[y],"\t",test1[y],"\t",test2[y],"\t",test3[y],"\t",total[y],"\t",avg[y])
if found == True:
print("Data found at : ", j)
else:
print("Data not in list")
for x in range(0,5):
print("For loop : ",x+1)
y=1
while y<=5:
print("While loop : ",y)
y=y+1
pid = 0
pname = 0
qty = 0
price = 0
total = 0
order = 0
gt = 0
order = int(input("Enter your orders"))
for x in range(1,order +1):
print("Order no : ", x)
pid = int(input("Enter product id :"))
if pid == 1:
pname = "shawarma"
price = 360
elif pid == 2:
pname = "Pizza"
price = 560
elif pid == 3:
pname = "pratharoll"
price = 120
qty = int(input("Enter product qty : "))
total = qty * price
print("Total bill : ",total)
gt = gt + total
print("Grand total :", gt)
def square(side):
area = 0
area = side * side
print("Area of square : ",area)
def rectangle(length,width):
area = 0
area = length * width
print("Area of rectangle : ",area)
def parallelogram(base,height):
area = 0
area = base * height
print("Area of parrallelogram : ",area)
def triangle(base,height):
area = 0
area = (base * height)* 0.5
print("Area of Triangle : ",area)
def trapezoid(b1,b2,h):
area = 0
area = 0.5*h*(b1+b2)
print("Area of Trapezoid : ",area)
def circle(radius):
area = 0
area = 3.142 * radius * radius
print("Area of Circle : ",area)
#main Program
square(20)
rectangle(20,40)
parallelogram(80,90)
triangle(40,60)
trapezoid(10,20,80)
circle(30)
def menu():
print("=========MainMenu=========")
print("1- shawarma 250 ")
print("2- pizza 450 ")
print("3- donner 500 ")
print("==========================")
print()
def bill(pid, qty):
price = 0
total = 0
if pid == 1 :
price = 250
elif pid == 2:
price = 450
elif pid == 3:
price = 500
total = qty * price
return total
def discount(total):
if total >= 5000 :
disc = total * 0.1
else:
disc = 0
return disc
def invoice(pid,pname,qty,price,total,discount):
netbill = total - discount
print("=========Invoice=========")
print("Pid : ", pid)
print("Pname : ", pname)
print("Qty : ", qty)
print("Price : ", price)
print("Total : ", total)
print("Disc : ", discount)
print("Bill : ", netbill)
print("==========================")
menu()
pid = 0
pname = 0
qty = 0
price = 0
total = 0
disc = 0
pid = int(input("Enter Product Id : "))
if pid == 1 :
pname = "shawarma"
price = 250
elif pid == 2 :
pname = "pizza"
price = 450
elif pid == 3 :
pname = "donner"
price = 500
max(200,40,30)
def sum(array):
total = 0
for x in range(0,len(array)):
total = total + array[x]
print("Sum is : ",total)
data = [8,2,3,0,7]
sum(data)
#validation m1 0-25 m2 0-35 m3 0-45
stname = 0
m1 = 0
m2 = 0
m3 = 0
total = 0
avg = 0
student = 0
student = int(input("Enter Total number of Student in
Class : "))
for x in range(student):
print("Student no : ", x + 1)
stname = input("Enter Student Name : ")
m1 = int(input("Enter Subject 1 marks : "))
while m1<0 or m1>25:
m1 = int(input("Error : Re Enter Subject 1 marks
between 0 to 25 : "))
m2 = int(input("Enter Subject 2 marks : "))
while m2<0 or m2>35:
m2 = int(input("Error : Re Enter Subject 2 marks
between 0 to 35 : "))
m3 = int(input("Enter Subject 3 marks : "))
while m3<0 or m3>45:
m3 = int(input("Error : Re Enter Subject 3 marks
between 0 to 45 : "))
total = m1 + m2 + m3
avg = total/3
print()
print("Student Name : ", stname)
print("Test 1 Marks : ", m1)
print("Test 2 Marks : ", m2)
print("Test 3 Marks : ", m3)
print("Total Marks : ", total)
print("Average Marks : ", avg)
data =[[0,0,0,0],[0,0,0,0],[0,0,0,0]]
gt = 0
for r in range(0,3):
for c in range(0,3):
data[r][c] = input("Enter Data : ")
for x in range(0,3):
data[x][3] = int(data[x][1]) * int(data[x][2])
gt = gt + data[x][3]
print("Pname\t","Qty\t","Price\t","Total")
for row in range(0,3):
for col in range(0,4):
print(data[row][col],end="\t")
print()
#maincode
mainmenu()
choice = 0
while True :
choice = int(input("Enter your Choice : "))
if choice == 1:
writing()
elif choice == 2:
reading()
elif choice == 3:
appending()
elif choice == 4:
break
else:
print("Wrong entry ")