如何编写程序来打印与用户给定的日期相对应的日期名称



我想要一个输入,比如如果我键入1,它将在周日给出输出,如果我键入2,它将给出周一。我试过这个代码,但它不起作用,请帮助

days =["Sunday" ,"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
user_input = int(input("Enter Day"))
if user_input == (1,2,3,4,5,6,7) :
print (days[0,1,2,3,4,5,6])

我想让我的程序变得简单,我是的初学者

days =["Sunday" ,"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
user_input = int(input("Enter Day (from 1-7)"))
if user_input:
print (days[user_input-1])
else:
print ("Your input is not valid")

使用字典

days_dict ={'1':"Sunday" ,'2':"Monday",'3':"Tuesday", '4':"Wednesday", '5':"Thursday", '6':"Friday", '7':"Saturday"}
print (days_dict[input("Enter Day (from 1-7): ")])
days =["Sunday" ,"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
user_input = int(input("Enter Day"))
print (days[user_input - 1])

这将有助于

day_number = int(input("Enter day number: "))
days = { 
1:'SUNDAY',
2:'MONDAY',
3:'TUESDAY',
4:'WEDNESDAY',
5:'THURSDAY',
6:'FRIDAY',
7:'SATURDAY'
}
print(days.get(day_number))

相关内容

  • 没有找到相关文章

最新更新