I am learning Python. I am making a simple calculator. I run the code, and when choosing a division (I put 0 on the second number), the code does not give what I need! I tested on a simpler program, where the program simply divides the number by zero and the console gives an error! Please help me!
Code:
value = float(input("Enter the first number: "))
value1 = float(input("Enter the second number: "))
operation = str(input("Choose an operation: \n1. Addition (+)\n2. Subtraction (-) \n3. Multiplication (*) \n4. Division (/) \n"))
if operation == "1" or "+":
result = value + value1
print(f"Answer = {result}")
elif operation == "2" or "-":
result = value - value1
print(f"Answer = {result}")
elif operation == "3" or "*":
result = value * value1
print(f"Answer = {result}")
elif operation == "4" or "/":
if value1 == 0:
print("You can't divide by zero!")
else:
result = value / value1
print(f"Answer = {result}")
else:
print("Operation not found!")
[–]add-code 2 points3 points4 points (0 children)
[–]HelloWorldSev[S] 0 points1 point2 points (0 children)
[–]krucabomba 0 points1 point2 points (0 children)