6.(程序题)
假设有三个列表:lst_who=[’小马’,小羊,小鹿’],lst_where=['草地上’,电影院,家里],lstwhat=[看电影’,听故事','吃晚饭’。试编写程序,用户输入三个0-2范围内的整数,将其作为索引分别访问三个列表中的对应元素,然后进行造句。如果用户输入的三个整数不符合要求,则输出“输入有误”。
用例1:输入--1,02
输出--
小羊在草地上吃晚饭
用例2:输入-132
输出--输入有误
回答:代码还是比较简单的,一些基础的语法,加油哦
lst_who = ['小马', '小羊', '小鹿']
lst_where = ['草地', '电影院', '家里']
lstwhat = ['看电影', '听故事', '吃晚饭']
print('输入三个0-2范围内的整数')
who = (int)(input('第1个: '))
where = (int)(input('第2个: '))
what = (int)(input('第3个: '))
if (who >= 0 and who <= 2) and (where >= 0 and where <= 2) and (what >= 0 and what <= 2):
print(lst_who[who] + '在' + lst_where[where] + lstwhat[what])
else:
print('输入有误')