lundi 16 août 2021

if statement in python 3.9 [closed]

hi so i tried to make a calculator on python, and I just started programming so this may be a rookie mistake, but I wanted to have python return "u know that ain't possible" when asked to divide by zero, but so far I've not been able to do it. i am linking my best attempt, in the hope you can help me out!

(p.s, I'm using python 3.9 and pycharm community)

num_1 = int(input("Enter a number :"))
operation = input("Enter operation type (+,-,x,/) :")
num_2 = int(input("Enter another number :"))

if operation == "+":
    print(num_1, "+", num_2, "=", num_1 + num_2)
elif operation == "-":
    print(num_1, "-", num_2, "=", num_1 - num_2)
elif operation == "/":
    if num_2 == "0":
        print("u know that ain't possible")
    else:
        print(num_1, "/", num_2, "=", num_1 / num_2)
elif operation == "x":
    print(num_1, "x", num_2, "=", num_1 * num_2)
else:
    print("invalid operator")

Aucun commentaire:

Enregistrer un commentaire