Python TypeError:-:“int”和“str”的不支持的操作数类型TypeError:

Python TypeError:-:“int”和“str”的不支持的操作数类型TypeError:,python,Python,嗨,我正在尝试学习python,但我似乎不知道问题出在哪里 # coding: utf8 print ("Hello write name to write your name! ") name = raw_input("What is your name") print ("Write age to put in your age") age = raw_input("How old are you") Thisyear = int(input("what year is it today:

嗨,我正在尝试学习python,但我似乎不知道问题出在哪里

# coding: utf8
print ("Hello write name to write your name! ")
name = raw_input("What is your name")
print ("Write age to put in your age")
age = raw_input("How old are you")
Thisyear = int(input("what year is it today: "))
year = str((Thisyear - age)+100)
print (name +" Will be 100 years old in the year " + year)
我一直在犯这个错误

File "dsdc.py", line 7, in <module>
        year = str((Thisyear - age)+100)
    TypeError: unsupported operand type(s) for -: 'int' and 'str`
age的值来自raw_输入,它返回一个字符串,而不是整数,因此当您对其执行数字操作时,它会引发TypeError异常

您应该将年龄转换为具有int的整数:


Thisyear是int类型的变量,year是str类型的变量。您正在尝试对不同的数据类型执行操作。仅供参考,您使用的python 2有点过时。相反,我建议您下载一个python 3解释器,它对初学者更为友好。
age = int(raw_input("How old are you"))