Lab 2

In this lab I used a while statement in order to create a loop. In order for the code to repeat the user had to enter 1 if they wished to do calculations or 2 if they wanted the program to end. As long as thier input was < 2 then the code would run forever.

Code:

o = input(‘Enter 1 to calculate numbers. Enter 2 to end\n’)
while o < 2:
X = input(‘Enter X value\n’)
Y = input(‘Enter Y value\n’)
Sum = X + Y
Sum = int(Sum)
Dif = X – Y
Prod = X * Y
Quot = X / Y
print’Sum is’
print Sum
print’Diffrence is is’
print Dif
print’Product is’
print Prod
print’Quotient is’
print Quot
o = input(‘Enter 1 to calculate numbers. Enter 2 to end\n’)lab2

Leave a Reply

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