Python Forum

Full Version: New to python, trying to make a basic calculator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, so I've got this piece of code that I put together that is pretty simple. However, when I execute the code it executes all the if statements instead of one. I know it has to be something wrong with my if statements, but I don't know what. Changing it to an elif doesn't help me. Any help would be appreciated. Thanks!

first_number = input("First Number: ")
first_number = int(first_number)

operator = input("Operation: ")

second_number = input("Second Number: ")
second_number = int(second_number)


for sign in operator:
	if sign == "*" or "x" or "multiply" or "times":
		print(first_number * second_number)
	if sign == "/" or "divide":
		print(first_number / second_number)
	if sign == "+" or "plus" or "add":
		print(first_number + second_number)
	if sign == "-" or "minus" or "subtract":
		print(first_number - second_number)
Also, if there's an easier solution to what I've made please let me know. Thanks!
Check https://python-forum.io/thread-121.html
Also better use if/elif instead of multiple separate ifs
(Apr-14-2022, 10:17 AM)buran Wrote: [ -> ]Check https://python-forum.io/thread-121.html
Also better use if/elif instead of multiple separate ifs

Awesome, thank you!