相关疑难解决方法(0)

如何将输入读作数字?

在下面的代码中为什么xy字符串而不是整数?网上的所有内容都说要使用raw_input(),但是我读input()raw_input()在Python 3.x中重命名的Stack Overflow(在一个不处理整数输入的线程上).

play = True

while play:

    x = input("Enter a number: ")
    y = input("Enter a number: ")

    print(x + y)
    print(x - y)
    print(x * y)
    print(x / y)
    print(x % y)

    if input("Play again? ") == "no":
        play = False
Run Code Online (Sandbox Code Playgroud)

python int input python-2.7 python-3.x

261
推荐指数
7
解决办法
76万
查看次数

不能将序列乘以'float'类型的非int

级别:初学者

为什么我得到错误"不能将序列乘以'int'类型的非int"?

def nestEgVariable(salary, save, growthRates):
    SavingsRecord = []
    fund = 0
    depositPerYear = salary * save * 0.01
    for i in growthRates:  
        fund = fund * (1 + 0.01 * growthRates) + depositPerYear
        SavingsRecord += [fund,]
    return SavingsRecord 


print nestEgVariable(10000,10,[3,4,5,0,3])
Run Code Online (Sandbox Code Playgroud)

谢谢巴巴

python floating-point sequence

34
推荐指数
2
解决办法
14万
查看次数

我收到类型错误。我如何解决它?

我经常从我的 Python 代码中得到未捕获的异常(错误),这些异常被描述为TypeErrors. 经过大量的实验和研究,我收集了以下示例(以及细微的变化):

TypeError: func() takes 0 positional arguments but 1 was given
TypeError: func() takes from 1 to 2 positional arguments but 3 were given
TypeError: func() got an unexpected keyword argument 'arg'
TypeError: func() missing 1 required positional argument: 'arg'
TypeError: func() missing 1 required keyword-only argument: 'arg'
TypeError: func() got multiple values for argument 'arg'
TypeError: MyClass() takes no arguments
TypeError: unsupported operand type(s) for +: 'int' and 'str'
TypeError: can only concatenate str …
Run Code Online (Sandbox Code Playgroud)

python debugging typeerror

11
推荐指数
2
解决办法
8049
查看次数