Lab#3 Python Program

# Lab3 the program displays a menu to the user with 7 options (operations).
# The user makes a selection and the program ask two integers
# numbers and performed the selected operation and displays the result.

# Function to inter two numbers and convert to integers
def two_numbers(a,b):
a_str=input(‘Please enter the first number: ‘)
b_str=input(‘Please enter the second number: ‘)
a=int(a_str)
b=int(b_str)
return a
return b
#****************************************************
# function to display menu
def menu():
print(“1- Sum numbers”)
print(“2- Subtract numbers”)
print(“3- Multiply numbers”)
print(“4- Divide numbers”)
print(“5- Remainder of numbers”)
print(“6- Compare numbers”)
print(“7- Exit “)
# function to calculate the sum of two numbers
def my_sum(a,b):
s=a+b
return s
# function to calculate the difference of two numbers
def my_diff(a,b):
d=a-b
return d
# function to calculate the product of two numbers
def my_prod(a,b):
p=a*b
return p
# function to calculate the quotient of two numbers
def my_quot(a,b):
q=a/b
q=int(q)
return q
# function to calculate the remainder of the division of two numbers
def my_remaind(a,b):
r=a%b
return r
# function to compare two numbers
def my_comp(a,b):
if a>b:
print(a, “is greater than”, b)
elif a==b:
print(“The two numbers are equal”)
else:
print(a, “is less than”, b)

#******************************************************

# Processing stage
choice=1
print(“MAKE YOUR CHOICE AND THE PROGRAMM WILL HELP YOU PROCESSING AND DISPLAY THE RESULT”)
while choice in [1, 2, 3, 4, 5, 6, 7]:
print(‘ ‘)
menu()
print(‘ ‘)
choice_str=input(‘Please make your choice [1, 2, 3, 4, 5, 6, 0r 7] : ‘)
print(‘ ‘)
choice=int(choice_str)
if choice in [1, 2, 3, 4, 5, 6]:
a_str=input(‘Please enter the first number: ‘)
b_str=input(‘Please enter the second number: ‘)
x=int(a_str)
y=int(b_str)
if x!=0 and y!=0:
print(‘ ‘)
print(‘ ‘)
if choice==1:
result=my_sum(x,y)
print(“THE SUM :”,x, “+ “, y, “=”, result)
elif choice==2:
result=my_diff(x,y)
print(“THE DIFFRENCE : “,x, “-“, y, “=”, result)
elif choice==3:
result=my_prod(x,y)
print(“THE PRODUCT : “, x, “*”, y, “=”, result)
elif choice==4:
result=my_quot(x,y)
print(“THE QUOTIENT : “, x, “/”, y, “=”, result)
elif choice==5:
result=my_remaind(x,y)
print(“THE REMAINDER : “,x, “%”, y, “=”, result)
elif choice==6:
result=my_comp(x,y)
else :
print(“Please enter an integer in [1,2,3,4,5,6,7]!”)
else:
print(‘One or both numbers you entered is 0’)
print(“GOOD BYE”)
break
else:
print(“GOOD BYE”)
break