我想能够有这个程序打印出一个答案,说像'对不起,我不认识,如果用户输入1-5以外的任何东西'。你知道吗
import time
rating=input()
if rating == '1':
time.sleep(.5)
print('Well, you mustve just had a bad day.')
if rating =='2':
time.sleep(.5)
print('Second to last means I wasnt even the best at losing...')
if rating =='3':
time.sleep(.5)
print('Atleast thats almost passing.')
if rating =='4':
time.sleep(.5)
print('Im offended.')
if rating =='5':
time.sleep(.5)
print('Well yeah, obviously.')
利用
if
、elif
和else
,如果输入不是1、2、3、4、5,那么代码中的else
将打印您想要显示的消息。由于elif
,下面的代码也将阻止检查所有其他数字。在代码中,您检查了5个if语句中的所有数字。你知道吗再次询问用户,直到输入正确的号码(根据您下面的评论)
输出(第二种情况)
相关问题 更多 >
编程相关推荐