Lab 2


Lab Description: I created a program that initially asks the user to input two integers for x and y. After the user inputs x and y, the program would display statements of operations. The program would then ask the user to choose which operation to compute the variables. After the program shows the results of the computations, it would again ask the user for x and y inputs. If user inputs 0 for both x and y, the program terminates.

Source Code:

while x !=0 or 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 = input(‘Enter your choice:’)

if selection == 1:

result = x+y

print (‘The sum of x and y is:’), result

elif selection == 2:

result = x-y

print (‘The difference of 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

else:

result = x<y, x==y, x>y,

print (‘Whether x is less than, equal, or greater than y:’), result

x=input (‘Enter 1st number:’)

y=input (‘Enter 2nd number:’)

print (‘You have entered zero, therefore program is terminated’)