lundi 28 août 2017

How do you make two options possible in if/else statements in Python 2.7? [duplicate]

I am trying to right a script based calculator in Python 2.7. I am using if/else statements so that the computer knows which operation the user wants to use. I tried this:

import time
while 1 == 1:
    num1 = raw_input("Number 1: ")
    num2 = raw_input("Number 2: ")

    sum = num1 + num2
    difference = num1 - num2
    product = num1 * num2
    quotient = num1 / num2

    operation = raw_input("Do you want:\n Sum\n Difference\n Product\n Quotient\n\n")
    if operation == "Sum" or "sum":
        print sum

    elif operation == "Difference" or "difference":
        print difference

    elif operation == "Product" or "product":
        print product

    elif operation == "Quotient" or "quotient":
        print quotient

    else:

    time.sleep(2)

However, the program no longer works. I was hoping someone could tell me the syntax for having to possible options in only one if/else statement. Thanks!

Aucun commentaire:

Enregistrer un commentaire