Lab Description:
In this example we use the same method as in Lab 2 ,but instead have an statement to exit the program.
Code:
x = int(input(‘Enter the 1st number: ‘))
y = int(input(‘Enter the 2nd number: ‘))
print (‘Enter 1 to add the numbers’)
print (‘Enter 2 to subtract the numbers’)
print (‘Enter 3 to multiply the numbers’)
print (‘Enter 4 to divide the numbers’)
print (‘Enter 5 to find the remainder of x%y’)
print (‘Enter 6 for x<=y’)
print (‘Enter 7 to exit the program’)
z = int(input(‘Enter your selection: ‘))
if z==1:
result = x+y
print (‘The sum of ‘,x,’ and ‘,y,’ is: ‘,result)
elif z==2:
result = x-y
print (‘The difference of ‘,x,’ and ‘,y,’ is: ‘,result)
elif z==3:
result = x*y
print (‘The product of ‘,x,’ and ‘,y,’ is: ‘,result)
elif z==4:
result = x/y
print (‘The quotient of ‘,x,’ and ‘,y,’ is: ‘,result)
elif z==5:
result = x%y
print (‘The remainder of ‘,x,’ and ‘,y,’ is: ‘,result)
else:
if x<=y:
if x = y then (‘The numbers are equals’,result)
elif x < y then (‘,x,’ is less than ‘,y,’,result)
elif x > y then (‘,x,’ is greater than ‘,y,’,result)
Screenshots: