【发布时间】:2018-01-09 20:11:13
【问题描述】:
所以当我试图运行这段代码时。如您所见,它要求输入一个数字。
print('How old is Vini?')
number= 17
guess= int(input('enter a number'))
if guess== number:
print('Bravo Vini is 17')
elif guess < number:
print('Vini is older than '+guess)
elif guess > number:
print('Vini younger than '+guess)
现在如果数字等于 17,它会执行,但如果数字更高或更低,它会给我这个错误:
当数字较大时:
Traceback (most recent call last):
File "C:\Users\ervin\Desktop\loja.py", line 9, in <module>
print('Vini younger than '+guess)
TypeError: must be str, not int
当数字较低时:
Traceback (most recent call last):
File "C:\Users\ervin\Desktop\loja.py", line 7, in <module>
print('Vini is older than '+guess)
TypeError: must be str, not int
【问题讨论】:
-
为什么您首先考虑的是重新安装python而不是调查错误消息?
-
见上文.. 并修正标题以避免过多的反动反对票。因为答案是:否,你应该修复你的代码。
-
我更倾向于
print('Vini is older than', guess),而不是使用转换和连接。 -
你不需要重新安装python,你需要rewrite python,这样你就可以像在Javaaaaah中那样添加带有整数的字符串
-
@Mangohero1:我认为这不适用。标题很差,但问题符合“itsnotworking”链接中提到的所有内容。
标签: python python-3.x