Python 根据数字打印星期几
Python print day name of week from number
我正在创建一个程序,我必须输入一个数字,当我 运行 该程序时,解决方案应该是该数字的日期。但我不知道该怎么做。我做的程序是这样的:
num = 4
if(num = 1)
print('Monday')
elif(num = 2)
print('Tuesday')
elif(num = 3)
print('Wednesday')
elif(num = 4)
print('Thursday')
elif(num = 5)
print('Friday')
elif(num = 6)
print('Sunday')
elif(num = 7)
print('Saturday')
elif(num < 1)
print('Put a number between 1 and 7')
else(num > 7)
print('Put a number between 1 and 7')
num = 0
while num <= 7:
num += 1
if num == 1:
print('Monday')
elif num == 2:
print('Tuesday')
elif num == 3:
print('Wednesday')
elif num == 4:
print('Thursday')
elif num == 5:
print('Friday')
elif num == 6:
print('Saturday')
elif num == 7:
print('Sunday')
在python中,for语句如if、for等。你必须在它的末尾添加:
。
为了比较(相等),您必须使用 ==
而不是 =
num = 4
if(num == 1):
print('Monday')
elif num == 2:
print('Tuesday')
.....
您可以不带括号进行比较,它也可以。
我正在创建一个程序,我必须输入一个数字,当我 运行 该程序时,解决方案应该是该数字的日期。但我不知道该怎么做。我做的程序是这样的:
num = 4
if(num = 1)
print('Monday')
elif(num = 2)
print('Tuesday')
elif(num = 3)
print('Wednesday')
elif(num = 4)
print('Thursday')
elif(num = 5)
print('Friday')
elif(num = 6)
print('Sunday')
elif(num = 7)
print('Saturday')
elif(num < 1)
print('Put a number between 1 and 7')
else(num > 7)
print('Put a number between 1 and 7')
num = 0
while num <= 7:
num += 1
if num == 1:
print('Monday')
elif num == 2:
print('Tuesday')
elif num == 3:
print('Wednesday')
elif num == 4:
print('Thursday')
elif num == 5:
print('Friday')
elif num == 6:
print('Saturday')
elif num == 7:
print('Sunday')
在python中,for语句如if、for等。你必须在它的末尾添加:
。
为了比较(相等),您必须使用 ==
而不是 =
num = 4
if(num == 1):
print('Monday')
elif num == 2:
print('Tuesday')
.....
您可以不带括号进行比较,它也可以。