Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建一个python程序,告诉我姓名和出生年份的年龄_Python_Python 3.x - Fatal编程技术网

创建一个python程序,告诉我姓名和出生年份的年龄

创建一个python程序,告诉我姓名和出生年份的年龄,python,python-3.x,Python,Python 3.x,雷蒙德1962 艾米1982 杰克1978 凯文1970 罗莎1981 查尔斯1970 特里1968 吉娜1978 我必须创建一个程序,询问用户他们想知道的人的姓名和年龄 # Storing name information names = ['Raymond', 'Amy', 'Jake', 'Kevin', 'Rosa', 'Charles', 'Terry', 'Gina'] # Assigning year of birth YOB = ['1962', '1982', '197

雷蒙德1962

艾米1982

杰克1978

凯文1970

罗莎1981

查尔斯1970

特里1968

吉娜1978

我必须创建一个程序,询问用户他们想知道的人的姓名和年龄

# Storing name information

names = ['Raymond', 'Amy', 'Jake', 'Kevin', 'Rosa', 'Charles', 'Terry', 'Gina']

# Assigning year of birth 

YOB = ['1962', '1982', '1978', '1970', '1981', '1970', '1968', ',1978']

# Assigning each name in the form of a string to an integer value

Raymond = 1962
Amy = 1982
Jake = 1978
Kevin = 1970
Rosa = 1981
Charles = 1970
Terry = 1968
Gina = 1978
a = 2019

names = input('Who is the person you want to know the age of')
print('Their age is:', a - names)

这就是我目前所拥有的

第22行:TypeError:Sub:“int”和的操作数类型不受支持 “str”


这是我运行时收到的错误消息

您不能从int中减去字符串。此外,YOB列表包含字符串,而不是数字

为什么不用字典呢

namesYOB = {
    'Raymond': 1962,
    'Amy': 1982,
    'Jake': 1978,
    'Kevin': 1970,
    'Rosa': 1981,
    'Charles': 1970,
    'Terry': 1968,
    'Gina': 1978
}
a = 2019

name = input('Who is the person you want to know the age of')

if name in namesYOB:
    print('Their age is:', a - namesYOB[name])
else:
    print('Specified person not found')