Search code examples
pythonpython-3.xoperand

Can't assign function to call or unsupported operand type(s) for -=: 'str' and 'int'


To take 1 away from the variable "glory", the variable needs to be an integer. When turning it into an integer I just receive: "Can't assign function to call".

import sys

glory = input("Glory charge: ")
glory_prev = glory
print(glory_prev)
pouch = 28
run_num = 0
nat_price = input("Nat price: ")

while True:
    run = input("You've done " + (str(run_num)) + " runs: ")
    if run == "a":
        (int(glory) -= 1
        pouch -= 1
        if glory == 0:
            print("New glory needed")
            glory = glory_prev
        if pouch == 0:
            print("Repair pouch")
            pouch = 28

    elif run == "q":
        sys.exit
    else:
        continue

Please help, thanks.


Solution

  • The only thing you have to consider is to remove bracket before int of glory and change that glory syntax to

    glory = int(glory) - 1
    

    so the code will be like this

    import sys
    
    glory = input("Glory charge: ")
    glory_prev = glory
    print(glory_prev)
    pouch = 28
    run_num = 0
    nat_price = input("Nat price: ")
    
    while True:
        run = input("You've done " + (str(run_num)) + " runs: ")
        if run == "a":
            glory = glory - 1
            pouch -= 1
            if glory == 0:
                print("New glory needed")
                glory = glory_prev
            if pouch == 0:
                print("Repair pouch")
                pouch = 28
    
        elif run == "q":
            sys.exit
        else:
            continue