#29626: python 求解..


gloyia17@gmail.com (glonyice)

學校 : 不指定學校
編號 : 187409
來源 : [123.194.168.213]
最後登入時間 :
2022-04-10 12:15:48

a=input()

b=a.split()

i=0

while i<2:

    c=eval(b[i])

    if c%4==0 and c%100!=0:

        print("閏年")

    elif c%400==0:

        print("閏年")

    else:

        print("平年")

    i=i+1

 

----

 

您的程式被監控系統中斷,可能是程式無法正常結束所導致。
Traceback (most recent call last):
  File "/9279086/code_9279086.py", line 5, in 
    c=eval(b[i])
IndexError: list index out of range

----

不知道哪裡錯了...


#29632: Re:python 求解..


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.12.66.21]
最後登入時間 :
2025-04-20 17:19:22

a=input()

b=a.split()

i=0

while i<2:

    c=eval(b[i])

    if c%4==0 and c%100!=0:

        print("閏年")

    elif c%400==0:

        print("閏年")

    else:

        print("平年")

    i=i+1

 

----

 

您的程式被監控系統中斷,可能是程式無法正常結束所導致。
Traceback (most recent call last):
  File "/9279086/code_9279086.py", line 5, in 
    c=eval(b[i])
IndexError: list index out of range

----

不知道哪裡錯了...



不知道為什麼你要這樣寫...

1. b的長度只有1,所以沒有b[1],其實連split都不需要

2. 多筆測資EOF結束

 

#29634: Re:python 求解..


gloyia17@gmail.com (glonyice)

學校 : 不指定學校
編號 : 187409
來源 : [123.194.168.213]
最後登入時間 :
2022-04-10 12:15:48

最近剛學...發現跟原先的想法比起來滿不成熟的

 

終於解出來了,只是不知道有沒有更好的(應該有吧 哈哈)

 

 

while True:

    try:

        a=input()

        c=eval(a)

    except EOFError:

        break

    if c%4==0 and c%100!=0:

        print("閏年")

    elif c%400==0:

        print("閏年")

    else:

        print("平年")

    

#29636: Re:python 求解..


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.12.66.21]
最後登入時間 :
2025-04-20 17:19:22

最近剛學...發現跟原先的想法比起來滿不成熟的

 

終於解出來了,只是不知道有沒有更好的(應該有吧 哈哈)

 

 

while True:

    try:

        a=input()

        c=eval(a)

    except EOFError:

        break

    if c%4==0 and c%100!=0:

        print("閏年")

    elif c%400==0:

        print("閏年")

    else:

        print("平年")

    


建議eval改成int,其他地方沒什麼問題

#29899: Re:python 求解..


yudie (yudie)

學校 : 不指定學校
編號 : 179358
來源 : [111.82.240.237]
最後登入時間 :
2024-01-08 06:31:27

最近剛學...發現跟原先的想法比起來滿不成熟的

 

終於解出來了,只是不知道有沒有更好的(應該有吧 哈哈)

 

 

while True:

    try:

        a=input()

        c=eval(a)

    except EOFError:

        break

    if c%4==0 and c%100!=0:

        print("閏年")

    elif c%400==0:

        print("閏年")

    else:

        print("平年")

    

這樣應該比較簡單一點點

year=[]

while True:

    try :

        year.append(int(input()))

    except :

        break

for i in range(len(year)):

    if (((year[i]%4==0) and (not(year[i]%100==0))) or (year[i]%400==0)):

        print("閏年")

    else:

        print("平年")