Lab 2

Lab Description:
Writing a script that lets the user choose from different options whether or not to run the body. The body lets the user choose two different values. The script runs basic arithmetic to calculate different answers based on what the user entered. The script also tells you which of the two numbers entered are larger/smaller or equal. In the end of the script it gives you the option to rerun the script or to close it.

Code:

userchoice = input ("choose an option: \n(1) choose x and y values \n(2) exit\n")

while userchoice == 1:
    x = input ("enter your x value: ")
    x = int(x)
    y = input ("enter your y value: ")
    y = int (y)

    print("\n")
    print("the sum:")
    print(x+y)

    print("\n")
    print("the difference:")
    print(x-y)

    print("\n")
    print("the product:")
    print(x*y)

    print("\n")
    print("the quotient:")
    if y == 0:
        print ("undefined; cannot divide by zero")
    elif y!= 0:
        print (x/y)

    print("\n")
    print("the remainder:")
    if y == 0:
        print ("undefined; cannot divide by zero")
    elif y!= 0:
        print (x%y)

    print("\n")
    if x == y:
        print ("x is equal to y")
    elif x > y:
        print ("x is greater than y")
    elif x <y:
        print ("x is less than y")

    print ("\n")
    userchoice = input ("would you like to choose another set of numbers? \n(1) yes \n(2) no (exit)\n")

if userchoice ==2:
    exit

else:
    exit

Screenshot:
lab 2

Leave a Reply

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