Personal information extraction (string)

Personal information extraction (string)

topic:

The user enters his personal information in the following format: To To

0122923450321 Wang Hao Law 1801 Hebei 2001
data respectively indicate: student number name, professional class, birth year, year of birth, space between each data To To

Some users did not enter data in accordance with the rules. When entering their year of birth, they wrote data similar to "born in 1900". The title guarantees that these users must start with four digits when entering the year To To

Please note that the program still needs to read the data correctly To To

Please follow the output style to output name, class, age To To

prompt To

The data in the list has the same index as the characters in the string, and the reference data is consistent with the slicing method.

code show as below:

n=input()
t=n.split(" ")#获取切片
print("姓名:"+t[1])
print("班级:"+t[2])
print("年龄:"+str(2020-int(t[4][0:4]))+"岁")#t[4][0:4]是第四个空格后四个数

Guess you like

Origin blog.csdn.net/qq_44250569/article/details/109584529