0
唯一の問題は、プログラムを実行しているときに、年、月、日を入力しても曜日が印刷されないことです。私は何が欠けているのでしょうか、少なくともヒントを得ることができますか?Pythonの初心者です。 Zellerのアルゴリズムに関する問題
これまでの私のプログラム(下記)です。心に留めておいて、私はPythonとコーディングにはまったく新しいので、大雑把なコードを許してください。
ありがとうございました!
デフメイン():
#Prompt User to enter year within range 1900 and 2100
year = eval(input("Enter year: "))
while(year < 1900 or year > 2100):
year = eval(input("Enter year: "))
print(year)
#Prompt User to enter month as a number
month = eval(input("Enter month: "))
while(month < 1 or month > 12):
month = eval(input("Enter month: "))
print(month)
#Prompt User to enter day as a number
day = eval(input("Enter day: "))
#Restrict the entry of numbered days based on the month and account for leap year in February
while((month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12) \
and (day > 31 or day < 1)):
day = eval(input("Enter day: "))
if(month == 2 and year % 4 == 0):
while(day < 1 or day > 29):
day = eval(input("Enter day: "))
print(day)
elif(month == 2):
while(day < 1 or day > 28):
day = eval(input("Enter day: "))
print(day)
if(month == 4,6,9,11):
while(day < 1 or day > 30):
day = eval(input("Enter day: "))
print(day)
#Change in year if month is January or February
if((month == 1) or (month == 2)):
year = year - 1
#Switch months so that March becomes the first month of the year and January/ February become the 11th and 12th months respectively
#Convert variables to algorithm variables (so a = month and b = day)
if(month < 3):
a = month + 10
else:
a = month - 2
b = day
c = year % 100
d = year // 100
#Compute r with algorithm
w = (13 * a - 1) // 5
x = c // 4
y = d // 4
z = w + x + y + b + c - 2 * d
r = z % 7
r = (r + 7) % 7
#Set conditions so r[0,6] prints a day of the week [Sunday == 0 , Saturday == 6]
if(r == 0):
print("The day is Sunday")
elif(r == 1):
print("The day is Monday")
elif(r == 2):
print("The day is Tuesday")
elif(r == 3):
print("The day is Wednesday")
elif(r == 4):
print("The day is Thursday")
elif(r == 5):
print("The day is Friday")
elif(r == 6):
print("The day is Saturday")
(メイン
)
エバールを使用しないでください:D:D:叫んで申し訳ありません。 'eval'が安全でないために' int(input()) 'を使用してください;) – HyperNeutrino