user_input = ("Enter a number and I will tell you the sum of the multiples of 3 and 5 leading up to it.")
number = int(user_input)
我只是想获取用户的输入并对其进行某些测试。例如,如果数字 > 0:。为了做到这一点,我假设用户输入数据自动存储为字符串,并且为了解决这个问题,可以执行代码框中提供的操作。然而,在执行此操作时,我得到 ValueError: invalidliteral for int() with base 10: 'Enter a number and I will告诉你 3 和 5 的倍数之和。'显然我做错了。有人可以阐明如何正确执行此操作吗?
-先感谢您 :)
您实际上并不是在提示输入号码。这user_input
在你的例子中是字符串文字Enter a number and I will tell you the sum of the multiples of 3 and 5 leading up to it.
,无法转换为数字。
可以提示用户输入input()
.
user_input = input("Enter a number and I will tell you the sum of the multiples of 3 and 5 leading up to it.")
number = int(user_input)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)