Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5 Calculator only does the + function GalaxyCoyote Silly Frenchman Posts: 35 Threads: 17 Joined: Apr 2019 Reputation: 0 Likes received: 1 #1 Jul-13-2019, 12:17 PM So I am working on this software that has a calculator it, yesterday it was working fine but after adding some operations it seems to only do addition. here is a snip of the code. Calcnumone = 0 Calcnumtwo = 0 Calcopcmd = 0 Calcop = 0 Calcop = int(input("What operation do you want?\n1)+\n2)-\n3)x\n4)÷\n5)Mod\n6)Rounding\n7)Ceil\n8)Floor\n")) if Calcop == 1 or "+": Calcnumone = int(input("What is your first number?: ")) Calcnumtwo = int(input("What is your second number?: ")) print("\n") print("Your answer is...") print(Calcnumone + Calcnumtwo) print("\n") continue elif Calcop == 2 or "-": Calcnumone = int(input("What is your first number?: ")) Calcnumtwo = int(input("What is your second number?: ")) print("\n") print("Your answer is...") print(Calcnumone - Calcnumtwo) print("\n") continue elif Calcop == 3 or "x" or "*": Calcnumone = int(input("What is your first number?: ")) Calcnumtwo = int(input("What is your second number?: ")) print("\n") print("Your answer is...") print(Calcnumone * Calcnumtwo) print("\n") continue elif Calcop == 4 or "/": Calcnumone = int(input("What is your first number?: ")) Calcnumtwo = int(input("What is your second number?: ")) print("\n") print("Your answer is...") print(Calcnumone / Calcnumtwo) print("\n") continue elif Calcop == 5 or "%": Calcnumone = int(input("What is your first number?: ")) Calcnumtwo = int(input("What is your second number?: ")) print("\n") print("Your answer is...") print(Calcnumone % Calcnumtwo) print("\n") continue elif Calcop == 6 or "round": Calcnumone = int(input("What do you want to round?: ")) Calcnumtwo = round(Calcnumone) print(Calcnumtwo) continue elif Calcop == 7 or "ceil": Calcnumone = int(input("What do you want to ceil?: ")) Calcnumtwo = ceil(Calcnumone) print(Calcnumtwo) continue elif Calcop == 8: Calcnumone = int(input("What do you want to floor?: ")) Calcnumtwo = floor(Calcnumone) print(Calcnumtwo) continueI am looking to fix the bug, not to improve on the code any other way. Thanks in advance! ichabod801 Bunny Rabbit Posts: 3,850 Threads: 84 Joined: Sep 2016 Reputation: 231 Likes received: 1164 #2 Jul-13-2019, 12:24 PM You need to have an expression on each side of the or. if Calcop == 1 or '+': is equivalent to if (Calcop == 1) or ('+'):. (see here for details) Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures Clunk_Head Silly Frenchman Posts: 41 Threads: 13 Joined: Jan 2019 Reputation: 0 Likes received: 3 #3 Jul-13-2019, 12:31 PM (Jul-13-2019, 12:24 PM)ichabod801 Wrote: You need to have an expression on each side of the or. if Calcop == 1 or '+': is equivalent to if (Calcop == 1) or ('+'):. (see here for details) Also you are casting your input to an int Calcop = int(input("What operation do you want?\n1)+\n2)-\n3)x\n4)÷\n5)Mod\n6)Rounding\n7)Ceil\n8)Floor\n")) Since your input can be an it or a string, just leave it as a string and adjust your tests for strings Calcop = input("What operation do you want?\n1)+\n2)-\n3)x\n4)÷\n5)Mod\n6)Rounding\n7)Ceil\n8)Floor\n") if Calcop == '1' or Calcop == '+': GalaxyCoyote Silly Frenchman Posts: 35 Threads: 17 Joined: Apr 2019 Reputation: 0 Likes received: 1 #4 Jul-13-2019, 12:35 PM note, this was part of a bigger piece, ignore some of the indenting errors « Next Oldest | Next Newest »

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)