dict_t = {'u': 'tuesday', 'h': 'thursday'}
dict_s = {'a': 'saturday', 'u': 'sunday'}
dict_week = {'m': 'monday', 'w': 'wednesday', 'f': 'friday', 't': dict_t, 's': dict_s}
first_1 = input("请输入第一个单词:")# 判断第一个字母 假如输入的是s
if first_1 in dict_week:
if first_1 == 't' or first_1 == 's':# 判断输入的第一个字母是不是s 或 t
first_2 = input("请输入第二个单词:")# 输入的是字母 假如输入的是a
if first_1 == 's':# 判断输入的字母是不是s
print(dict_s[first_2])
elif first_1 == 't':# 判断输入的字母是不是t
print(dict_s[first_2])
else:
print(dict_week[first_1])
python用前第一第二字母索引字典
最新推荐文章于 2021-10-25 17:13:03 发布