'Python if does not behave as expected
I was trying to make a python calculator. But for some reason it will only output the square-root option.
I am currently using python3.4 and 3.3 emulator on my iPhone, but it has the same problem on both devices.
print("This program is a calculator app \n Creator: AtPython")
print("...")
Print("please choose a mathematical operation")
Opt = input("square-root. \n addition, \n subtraction, \n multiplication, \n division: ")
if opt == "square-root" or "squareroot":
num = float(input('Enter a number: '))
num_sqrt = num ** 0.5
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
input("Press 'Enter' to exit")
If opt == "addition":
add_1 = float(input("Please enter a number"))
add_2 = float(input("Please enter another number"))
add_ans = add_1 + add_2
print(add_ans)
qus = input("Would you like to add another number? [y/n]")
elif qus == "y":
add_3 = float(input("Enter a third number"))
input("Press 'Enter' to exit")
else:
input("Press 'Enter' to exit")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|