0% found this document useful (0 votes)
3 views

Pseudocode Practice Python

Uploaded by

mustajabffgaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Pseudocode Practice Python

Uploaded by

mustajabffgaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

PSEUDOCODE PRACTICE PYTHON SHEET

Write Algorithms of following given python codes using these stated examples

Example: 1

total = 0

DECLARE TOTAL: INTEGER = 0

Example: 2

Number = int(input(“Input Number”))

OUTPUT ”INPUT NUMBER”

INPUT Number

Example: 3

print(“Your number is ” , Number)

OUTPUT “ Your number is ” , Number

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

NAVID SAQIB: +923334259883 1


PSEUDOCODE PRACTICE PYTHON SHEET

Example: 5

Price = [0,0,0,0,0]

DECLARE Price:ARRAY[1: 5] OF INTEGER

NAVID SAQIB: +923334259883 2


PSEUDOCODE PRACTICE PYTHON SHEET

PYTHON CODES Pseudocode


Feel = 0
Exercise = 0
Feel = input("ENTER HOW YOU FEEL :")
Exercise = input("Want to do Exercise ? :")
if Feel == "sad" and Exercise == "no" :
print("Go for a walk, you might feel better")
else:
print("Sorry I don't know how to help")
x=0
x = int(input("Enter X value : "))
if x > 0 :
print("pos value ")

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"

NAVID SAQIB: +923334259883 3


PSEUDOCODE PRACTICE PYTHON SHEET

print(drink, " can dropped, Thanks for your


Purchase")
if choice <1 or choice > 4:
print("wrong choice")
else:
print("Wrong Currency ")
pname = 0
qty = 0
type = 0
price = 0
total = 0
pid = 0
pid = int(input("Enter product Id :"))
type = input("Enter product Type : ")
if pid == 1 and type == "s":
pname = "pizza"
price = 340
elif pid == 1 and type == "m":
pname = "pizza"
price = 500
elif pid == 1 and type == "l":
pname = "pizza"
price = 900
elif pid == 2 and type == "s":
pname = "Shawarma"
price = 120
elif pid == 2 and type == "m":
pname = "Shawarma"
price = 320
elif pid == 2 and type == "l":
pname = "Shawarma"
price = 520
elif pid == 3 and type == "s":
pname = "Donner"
price = 380
elif pid == 3 and type == "m":
pname = "Donner"
price = 580
elif pid == 3 and type == "l":
pname = "Donner"
price = 780
else:
print("Not avaialable")
qty = int(input("Enter Qty : "))

total = qty * price

NAVID SAQIB: +923334259883 4


PSEUDOCODE PRACTICE PYTHON SHEET

if total > 3000:


disc = total *0.15
else:
disc =0
print("==========Invoice==============")
print("Pid : ", pid)
print("pname : ",pname)
print("price : ",price)
print("qty : ",qty)
print("type : ",type)
print("total : ",total)
print("Disc : ",disc)
print("Netbill :",total - disc)
print("===============================")
print(" Thankyou for your service ")
product = [0,0,0,0]
for x in range(0,4):
print("product no : ",x+1)
product[x] = input("Enter product Name : ")

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 : ")

NAVID SAQIB: +923334259883 5


PSEUDOCODE PRACTICE PYTHON SHEET

tfine = tfine + fine


else:
print("Normal Speed")

print("Total fine collection : ",tfine)


choice = 0
num1 = 0
num2 = 0
total = 0
while True:
print()
print("---------MainMenu--------")
print("1- Addition ")
print("2- Subtruction")
print("3- Multiply")
print("4- Division")
print("5- Quit Application")
print("-------------------------")
print()
choice = int(input("Enter your choice : "))
if choice != 5:
num1 = int(input("Enter num1 : "))
num2 = int(input("Enter num2 : "))
if choice == 1:
total = num1 + num2
print("Addition is : ", total)
elif choice == 2:
total = num1 - num2
print("Subtraction is : ", total)
elif choice == 3:
total = num1 * num2
print("Multiply is : ", total)
elif choice == 4:
total = num1 / num2
print("Division is : ", total)
elif choice == 5:
print("End of the program:")
break;
nums = [12,8,3,1]
temp = 0
for x in range(0,3):
for y in range(0,3):
if nums[x]<nums[x + 1]:
temp = nums[x]
nums[x] = nums[x + 1]
nums[x + 1] = temp

NAVID SAQIB: +923334259883 6


PSEUDOCODE PRACTICE PYTHON SHEET

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"

NAVID SAQIB: +923334259883 7


PSEUDOCODE PRACTICE PYTHON SHEET

elif marks < 40 :


grade = "Fail"
else:
print("Wrong Data : ")
print("Stname : ",stname, " Marks : ", marks , " Grade :
", grade)
stname = [0,0,0,0]
test1 = [0,0,0,0]
test2 = [0,0,0,0]
test3 = [0,0,0,0]
total = [0,0,0,0]
avg = [0,0,0,0]
grandtotal = 0
for x in range(0,4):
stname[x] = input("Enter Student Name : ")
test1[x] = int(input("Enter Test 1 marks : "))
while test1[x]<0 or test1[x]>40:
test1[x] = int(input("Error : Re Enter Test 1 marks 0 to 40 only: "))
test2[x] = int(input("Enter Test 2 marks : "))
while test2[x]<0 or test2[x]>50:
test2[x] = int(input("Error: Re Enter Test 2 marks 0 to 50 only : "))
test3[x] = int(input("Enter Test 3 marks : "))
while test3[x]<0 or test3[x]>60:
test3[x] = int(input("Error: Enter Test 3 marks 0 to 60: "))
total[x] = test1[x] + test2[x] + test3[x]
avg[x] = total[x]/3
grandtotal = grandtotal + total[x]
print()
print("Stname\t","Test1\t","Test2\t","Test3\t","Total\t","Avg")
for y in range(0,4):

print(stname[y],"\t",test1[y],"\t",test2[y],"\t",test3[y],"\t",total[y],"\t",avg[y])

print("Grand Total : ",grandtotal)


nums = [12,8,3,1]
item = 0
found = False
j=0
item = int(input("Enter item to search : "))
for x in range(0,4):
if item == nums[x]:
found = True
j=x

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

NAVID SAQIB: +923334259883 8


PSEUDOCODE PRACTICE PYTHON SHEET

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):

NAVID SAQIB: +923334259883 9


PSEUDOCODE PRACTICE PYTHON SHEET

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("==========================")

NAVID SAQIB: +923334259883 10


PSEUDOCODE PRACTICE PYTHON SHEET

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

qty = int(input("Enter Qty : "))


total = bill(pid, qty)
disc = discount(total)
invoice(pid, pname, qty, price, total, disc)
def max(n1,n2,n3):
if n1>n2 and n1>n3:
print("N1 is Max")
elif n2>n1 and n2>n3:
print("N2 is Max")
elif n3>n1 and n3>n2:
print("N3 is Max")
else:
print("Wrong data")

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

NAVID SAQIB: +923334259883 11


PSEUDOCODE PRACTICE PYTHON SHEET

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()

NAVID SAQIB: +923334259883 12


PSEUDOCODE PRACTICE PYTHON SHEET

print("Grand Total :",gt)


def writing():
#writing
f = open("data.txt","w")
s = input("Enter data to be entered in file : ")
f.write(s)
f.close()
print("File written Successfully : ")
def reading():
#reading
f = open("data.txt","r")
c = f.read()
f.close()
print("File Data : ", c)
def appending():
#Appending
f = open("data.txt","a")
s = input("Enter data to be Appended in file : ")
f.write(s)
f.close()
print("File Appended Successfully : ")
def mainmenu():
print("=======MainMenu======")
print("1-write file ")
print("2-read file ")
print("3-Append file ")
print("4-quit application ")
print("=====================")
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 ")

NAVID SAQIB: +923334259883 13


PSEUDOCODE PRACTICE PYTHON SHEET

print("Program Ended ")

NAVID SAQIB: +923334259883 14

You might also like