def check_age():
# 定义存储字典的列表
person_list = [
{'name': 'Alice', 'age': 20},
{'name': 'Bob', 'age': 16}
]
try:
# 获取用户输入
input_str = input("请输入字符串: ")
# 标记是否找到匹配
found = False
for person in person_list:
# 检查字典结构是否正确
if not isinstance(person, dict) or 'name' not in person or 'age' not in person:
continue
if input_str in person['name']:
found = True
try:
age = int(person['age'])
if age > 18:
print('成年')
else:
print('未成年')
except (ValueError, TypeError):
print('年龄数据异常')
break
if not found:
print('未找到')
except (EOFError, KeyboardInterrupt):
print('输入中断')
except Exception as e:
print(f'发生错误: {e}')
if __name__ == "__main__":
check_age()