Lab 2

Howard_lab2

Lab Description:

In this lab we learn how to computate boolean logic, boolean expressions, logical operators, If and if/else statements, loops. The program was hard to configure at first but with enough trial and error, a solution was found so the program could continue to run properly.

Code:

x = int(input(‘Enter 1st number: ‘))
y = int(input(‘Enter 2nd number: ‘))
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 reminder x%y’)
print (‘6 – Whether x is less than, equal, or greater than’)

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

x = input (‘Enter 1st number: ‘)
y = input (‘Enter 2nd number: ‘)

Screenshot

untitledlab1