对于以10为底的int()来说,无效文字是什么:“无”

时间:2018-12-19 01:47:22

标签: python-3.x

我刚开始使用python编程,因为我正在尝试学习编程,因为它在尝试获得理想工作时会很有用。因此,我尝试制作一个计算器,但收到此消息“以int()为基数10的无效文字:'None'”

在此,我做了一个过于复杂的计算器,我想这样做,以便重复执行这些步骤。在这种情况下,我希望它能够将第一个数字更改为上一个答案的答案,以便您可以乘以一个答案,然后乘以该答案,但是对于以10为底的int()我会得到无效的文字:“无”

1 个答案:

答案 0 :(得分:0)

您正在尝试将模块强制转换为整数,这并不完全正确。

您的算法应如下所示

currentValue = None
while True:
    number = int(input('give me a number'))
    next = input('yes to restart, Yes to continue)
    if next == 'yes':
       anotherNumber = int(input('give me another number'))
       currentValue = number * anotherNumber
    elif next == 'Yes':
       currentValue = number * currentValue
    else:
       print('Bye')
       break

    print('Total', currentValue)