Lab 2

Description:

This program asks the user to enter two integer numbers x and y. The program should perform the following operations and display the results back:

1-      The sum x + y

2-      The difference x – y

3-      The product x * y

4-      The quotient x/y

5-      The remainder x%y

6-      Whether x is less than, equal, or greater than y

After displaying the results, the program should ask again for two integer numbers and repeat the operations for the new values entered. If either the value of x or y entered by the user is 0 (zero), the program should finish.

 

# Usman Sethy
# Lab 2 – control flow
# 09/30/2013

x = float(input(‘Input the 1st number: ‘))
y = float(input(‘Input the 2nd number: ‘))
while x!=0 and y!=0:
print(‘———————————–‘)
print ‘1 – The sum x + y’
print ‘2 – The difference x – y’
print ‘3 – the product x * y’
print ‘4 – The quotient x/y’
print ‘5 – The remainder x%y’
print ‘6 – Whether x is less than, equal, or greater than y’
print(‘———————————–‘)
selection = input(‘please enter a selection: ‘)
if selection ==1:
result = x + y
print (“The sum of “,x,” and “,y,” is: “), result
elif selection ==2:
result = x – y
print (“The diffrence between “,x,” and “,y,” is: “), result
elif selection ==3:
result = x * y
print (“The product of “,x,” and “,y,” is: “), result
elif selection ==4:
result = x / y
print (“The quotient of “,x,” and “,y,” is: “), result
elif selection ==5:
result = x % y
print (“The remainder of “,x,” and “,y,” is: “), result
elif selection ==6:
if x < y:
print x, (“is less than”), y
elif x == y:
print x, (“is equal to”), y
else:
print x, (“is greater than”),y
print(‘———————————–‘)
x = input(‘Input the 1st number: ‘)
y = input(‘Input the 2nd number: ‘)

print(‘You have entered 0. Good Bye!’)

This is the screenshot of my program