LAB 2 – Control Flow

The objective of this was to write a program that asks the user to enter two integer numbers x and y. The program should ask the user to select one of the following operations and display the results back:

1-    The sum 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

During my process of creating this program the most difficult part was creating the program within the while loop. I had to manipulate my script so that the program can run without any syntax or indentation errors.

 

# Breder Jean Baptiste
# Lab 2 – Controol Flow
# 2/28/13
# Section: 9306
x = int(input (‘enter 1st number x: ‘))
y = int(input (‘enter 2nd number y: ‘))
while x!=0 and y!=0:

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’

selection = int(input (‘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 difference between” , x,’and’, y, “is: “,result)
elif selection == 3:
result = x * y
print (“The product between”, x, ‘and’ , y, “is: “,result)
elif selection == 4:
result= x / y
print (“The quotient between”, x, ‘and’, y, “is: “,result)
elif selection == 5:
result = x % y
print (“The remainder between”, x, “and”, y, “is: ” ,result)
elif selection == 6:
if x>y:
print(‘x is greater than y’)
elif x<y:
print (‘x is less than y’)
else:
print(‘x and y are equal’)

x = int(input (‘enter 1st number x: ‘))
y = int(input (‘enter 2nd number y: ‘))
print (‘ you have entered zero. End of program.’)