Python Can';t为-=:';str';和';int';

Python Can';t为-=:';str';和';int';,python,python-3.x,operand,Python,Python 3.x,Operand,要从变量“glory”中减去1,该变量必须是整数。当将其转换为整数时,我只收到:“无法将函数分配给调用” 请帮助,谢谢。 < P>你唯一要考虑的是在荣耀之前删除括号,把荣耀语法改为 glory = int(glory) - 1 所以代码是这样的 import sys glory = input("Glory charge: ") glory_prev = glory print(glory_prev) pouch = 28 run_num = 0 nat_price = input("Nat

要从变量“glory”中减去1,该变量必须是整数。当将其转换为整数时,我只收到:“无法将函数分配给调用”


请帮助,谢谢。

< P>你唯一要考虑的是在荣耀之前删除括号,把荣耀语法改为

glory = int(glory) - 1
所以代码是这样的

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

你希望
(int(glority)->=1做什么?从glority
int(glority)中去掉1
使用参数
glori
调用函数
int
。它可能会返回一个整数。然后您尝试执行类似
10-=1
的操作,这并没有让我感到不理解,因为我对python很陌生。当然这只意味着glori将等于9?这也是语法错误我使用的Python3.5无法分配要调用的函数,因为您只是以不正确的方式提供函数输入。每当您在=运算符的左侧编写函数并为其分配任何值时,它都会给出类似ex:a=3;int(a)的错误=4;虽然这是正确的,但我觉得在每次迭代中都将glori转换为int很奇怪。为什么不在开始时只执行一次呢?哈哈,你不需要输入cast,而且python的输入函数只将输入作为int,所以glori本身就是int,所以不需要将glori转换为int返回值,只有你可以看到通过以下代码a=input()#input 3;键入(a)#它将打印int
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