0

am trying to make a simple calculator using python but for some reason he keep giving me the same result everytime

here is the code

def inputing(num2, op)  :
    op = input("operator")
    num2 = int(input("number"))

def calculing(num1,num2,op):
    if op == "+":
        num1 += num2
        print(num1)
    elif op == "-":
        num1 -= num2
        print(num1)
    elif op == "*":
        num1 *= num2
        print(num1)
    elif op == "/":
        num1 /= num2
        print(num1)
    elif op == "=":
        print(num1)
    else:
        print("error")

repeat=True
class calcul():
    num1 = int(input("number"))
    op = input("operator")
    while op == "=":
        print(num1)
        op = input("operator")
    num2 = int(input("number"))
    while repeat==True:
        calculing(num1,num2,op)
        inputing(num2,op)

i want to take the first result and as the number1 then add the number2 to him and keep repeating that but here the result in console:

number:5
operator:+
number:5
10
operator:+
number:5
10
  • Your `calculating` function *prints* various things but *returns* nothing. It doesn't modify the passed variable. You seem to not understand how functions work in Python. Your `inputing` is also a function with no effect. – John Coleman Feb 01 '21 at 00:54
  • You might want to read up on variable scope in functions. While `global` is possible, it's usually considered cleaner to explicitly return and assign the variable. – user202729 Feb 01 '21 at 00:55

0 Answers0