Python TypeError:必须是str,而不是int(基本用户)

Python TypeError:必须是str,而不是int(基本用户),python,input,Python,Input,我是Python新手,只是在学习基础知识。请你帮我纠正一下,告诉我我是怎么错的,为什么错的 age = input('Please enter your age:') ten = 10 agePlusTen= age + ten print('You will be', agePlusTen, 'in 10 years' 回溯(最近一次呼叫最后一次): 文件“C:/Users/Admin/Documents/Python/6.2 fixed.py”,第3行,在 打印('你将,'岁+十,'十年

我是Python新手,只是在学习基础知识。请你帮我纠正一下,告诉我我是怎么错的,为什么错的

age = input('Please enter your age:')
ten = 10
agePlusTen= age + ten
print('You will be', agePlusTen, 'in 10 years'

回溯(最近一次呼叫最后一次):
文件“C:/Users/Admin/Documents/Python/6.2 fixed.py”,第3行,在
打印('你将,'岁+十,'十年')
TypeError:必须是str,而不是int
在python中,返回字符串。因此,您应该首先将
age
强制转换为
int
,然后将其添加到变量
ten

以下几点应该行得通

age = input('Please enter your age:')
ten = 10
agePlusTen= int(age) + ten
print('You will be ' + str(agePlusTen) + ' in 10 years')
另外,当您想要通过连接一组字符串来打印字符串时,如果其中任何字符串不是字符串,请不要忘记使用
str()
函数将其转换为字符串。

在python中,返回字符串。因此,您应该首先将
age
强制转换为
int
,然后将其添加到变量
ten

以下几点应该行得通

age = input('Please enter your age:')
ten = 10
agePlusTen= int(age) + ten
print('You will be ' + str(agePlusTen) + ' in 10 years')

另外,当您想通过连接一组字符串来打印字符串时,如果其中任何字符串不是字符串,请不要忘记使用
str()
函数将其转换为字符串。

在python中,使用时始终返回字符串。也就是说,当使用input()存储变量时,变量将始终为string类型,从而将age变量转换为整数写入,如下所示:
age=input('请输入您的年龄:')
十=十
agePlusTen=int(年龄)+10
打印('你将,'年龄加成,'在10年内'),


我认为这应该行得通。

在python中使用时,它总是返回字符串。也就是说,当使用input()存储变量时,变量将始终为string类型,从而将age变量转换为整数写入,如下所示:
age = input('Please enter your age:')
ten = 10
agePlusTen= int(age) + ten
print('You will be ' + str(agePlusTen) + ' in 10 years')
age=input('请输入您的年龄:')
十=十
agePlusTen=int(年龄)+10
打印('你将,'年龄加成,'在10年内'),


我想这应该行。

input
返回一个字符串。在做数学之前应用
int
这是一个巨大的重复,但我想不出类似的问题atm。为什么你把10作为那样的变量?我也是一个新手,所以我不会理解其他“高级”帖子的答案。我只是在处理变量和尝试随机的东西,但我会简化。
input
返回一个字符串。在做数学之前应用
int
。这是一个巨大的重复,但我想不出类似的问题。为什么你把10作为一个变量呢?我也是一个新手,所以我不会理解其他“高级”帖子的答案。我只是在处理变量和尝试随机的东西,但我会简化。这里有更多
age = input('Please enter your age:')
ten = 10
agePlusTen= int(age) + ten
print('You will be ' + str(agePlusTen) + ' in 10 years')