lab 2


This lab showed how python can be used to preform operation and how complex these operations could be taken which shows how useful python can be on a large scale. In the lab shown below, student were asked to show a mathematical operation base on algebraic math problems. As the program ran it asked for inputs of the X and Y variable and then performed the operation of choice, from addition to multiplication.





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


y = input (‘place 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’)




choice = input (‘enter your choice’)


if choice == 1:


result = x + y


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


elif choice == 2:


result = x – y


print (‘the difference between x and y is ‘,result)


elif choice == 3:


result = x * y


print (‘The product x * y is ‘,result)


elif choice == 4:


result = x/y


print (‘The quotient x/y is ‘,result)


elif choice == 5:


result = x%y


print (‘The reminder x%y is ‘,result)


elif choice == 6:


if x > y:


print (x,”is greater than”, y)


elif x < y:


print(x,”less than”, y)




print(x,”equal to”,y)


else :


print(“Enter a wrong selection”)



Leave a Reply

Your email address will not be published. Required fields are marked *