iT邦幫忙

0

求救 zerojudge f708: 蟲蟲危機 (Insect)

這段代碼哪裡錯了?

def solve(a,g):
    if sum(a)>sum(g):
        return(Yes)
    if sum(a)<=sum(g):
        return(No)
try:
    while True:
        M,N=map(int,input().split())
        a, b = map(int, input().split())
        if M<N:
            print('No')
        if M>N:
            ants=list(map(int(),input().split()))
            grasshoppers=list(map(int(),input().split()))
            print(solve(ants,grasshoppers))
except EOFError:
    pass

謝謝

2021-4-20
感謝AndyChiang提醒,已將網址補上
連結在此: https://zerojudge.tw/ShowProblem?problemid=f708

froce iT邦大師 1 級 ‧ 2021-04-20 07:56:18 檢舉
這題只考基本語法而已...
自己練習debug吧。
也不用寫這麼多code。

然後這題很明顯是從別的語言弄過來的題目。
前面輸入個數的部份在python不太需要。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
froce
iT邦大師 1 級 ‧ 2021-04-20 08:14:55
最佳解答
ants = []
grasshoppers = []
try:
    ants = [int(i) for i in input().split(",")]
    grasshoppers = [int(i) for i in input().split(",")]
except:
    print("format error")
    raise
    
if len(ants)>len(grasshoppers) and sum(ants) > sum(grasshoppers):
    print("Ants, go to fight!!!")
else:
    print("Ants are chicken")
1
Andy Chiang
iT邦新手 4 級 ‧ 2021-04-20 01:51:08

至少把題目內容和要做什麼放上來吧...
只貼程式碼上來我要怎麼知道哪裡錯...

可以講一下你這段code想要完成的事情

0
海綿寶寶
iT邦大神 1 級 ‧ 2021-04-20 09:44:06

Yes

1092B0007 iT邦新手 3 級 ‧ 2021-04-20 18:03:08 檢舉

這個影片我之前有看過了

我要發表回答

立即登入回答