Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Calculator only does the + function
#1
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!
Quote
#2
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

Quote
#3
(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 == '+':
Quote
#4
note, this was part of a bigger piece, ignore some of the indenting errors
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)