Lab 3

For this lab i rewrote lab#2 this time by using functions, my experience with this lab was a bit frustrating because of the syntax errors i keep getting but manage to get through it.

Code:

# define functions

def sum_numbers():

x= int(input (“enter integer x value:”))

y= int(input (“enter integer y value:”))

print (“x+y= “,(x+y))

def subtract_numbers():

x= int(input (“enter integer x value:”))

y= int(input (“enter integer y value:”))

print (“x-y= “,(x-y))

def multiply_numbers():

x= int(input (“enter intger x value:”))

y= int(input (“enter integer y value:”))

print (“x*y= “,(x*y))

 

def divide_numbers():

x= int(input (“enter integer x value:”))

y= int(input (“enter integer y value:”))

print (“x/y= “,(x/y))

def remainder():

x= int(input (“enter integer x value:”))

y= int(input (“enter integer y value:”))

if x==0 or y==0:

print (“The calculation is not possible”)

else:

print (“x%y= “,(x%y))

def compare():

x= int(input (“enter integer x value:”))

y= int(input (“enter integer y value:”))

if (x>y):

elif x<y:

print(‘x is less then y’)

else:

print(‘x and y are equal’)

# print menu on the screen

print(“”)

print (“Main Menu”)

print (“1- Sum of numbers”)

print (“2- Subtraction of numbers”)

print (“3- Multiplication of numbers”)

print (“4- Division of numbers”)

print (“5- Remainder of numbers”)

print (“6- Compare numbers”)

print (“7- Exit”)

print (“”)

# menu selection

x= int(input(“ select an option from menu:”))

if x==1:

sum_numbers()

elif x==2:

subtract_numbers()

elif x==3:

multiply_numbers()

elif x==4:

divide_numbers()

elif x==5:

remainder()

elif x==6:

compare()

if x==7:

exit

# create a loop to restart the program

while x!=7:

print (“”)

print (“Main Menu”)

print (“1- Sum of numbers”)

print (“2- Subtraction of numbers”)

print (“4- Division of numbers”)

print (“5- Remainder of numbers”)

print (“6- Compare numbers”)

print (“7- Exit”)

print (“”)

x= int(input(“ select an option from menu:”))

if x==1:

sum_numbers()

elif x==2:

subtract_numbers()

elif x==3:

multiply_numbers()

elif x==4:

divide_numbers()

elif x==5:

remainder()

elif x==6:

compare()

if x==7:

break