Answer the question
In order to leave comments, you need to log in
Why is the code in the if block executed even if the condition is false?
I am writing my own calculator and I want the user to re-enter the data if the input is incorrect, but until the correct one is entered
what = input("Выберу операцию(+),(-),(*),(/):")
if what == "+" or "-" or "*" or "/":
a = int(input("Первое число: "))
b = int(input("Второе число: "))
c = 0
if what == "+":
c = a + b
elif what == "-":
c = a - b
elif what == "*":
c = a * b
elif what == "/":
c = a / b
print(c)
else:
i = True
while i == True:
print("Неверная команда! Используй только '+','-','*','/':")
what = input("Выберу операцию(+),(-),(*),(/):")
if what == "+" or "-" or "*" or "/":
i = False
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question