Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Calculator only does the + function GalaxyCoyote Silly Frenchman Posts: 21 Threads: 10 Joined: Apr 2019 Reputation: 0 Likes received: 0 #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) continue```I am looking to fix the bug, not to improve on the code any other way. Thanks in advance! ichabod801 Bunny Rabbit Posts: 3,365 Threads: 70 Joined: Sep 2016 Reputation: 176 Likes received: 1031 #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: 35 Threads: 10 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: 21 Threads: 10 Joined: Apr 2019 Reputation: 0 Likes received: 0 #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

 Possibly Related Threads... Thread Author Replies Views Last Post Simple Calculator Help destr0yer667 1 143 May-22-2019, 02:11 PM Last Post: ichabod801 Problems with calculator muachihiyo 3 208 May-02-2019, 06:12 PM Last Post: ichabod801 AssertionError: View function mapping is overwriting an existing endpoint function Zhavi221 7 704 Apr-17-2019, 01:07 PM Last Post: Zhavi221 Value Estimator Calculator jaycuff13 1 171 Apr-03-2019, 12:52 PM Last Post: j.crater Value Estimator Calculator getting a TypeError jaycuff13 2 256 Apr-01-2019, 09:40 AM Last Post: jaycuff13 Extending my text file word count ranker and calculator Drone4four 8 728 Jan-25-2019, 08:25 AM Last Post: steve_shambles GPA Calculator Aldmonjoy 1 326 Jan-16-2019, 06:48 PM Last Post: ichabod801 Help with simple tip calculator DragonG 5 695 Oct-23-2018, 04:54 AM Last Post: snippsat Python Program to Make a Simple Calculator jack_sparrow007 2 2,121 Oct-19-2018, 08:32 AM Last Post: volcano63 Bill calculator with different prices JHPythonLearner 10 751 Sep-15-2018, 12:14 AM Last Post: volcano63

Forum Jump:

Users browsing this thread: 1 Guest(s)