簡體   English   中英

我在做項目時遇到了 EOFError,我不知道如何修復它

[英]I got An EOFError while doing a project and I don't know how to fix it

賦值賦值/代碼代碼code2 code3

if __name__ == '__main__': # Do not modify
    # FiLL array with five dice from input
    dice = [int(val) for val in input().split()]
    high_score = 0
    # PLace dice in ascending order
    dice.sort()
    print(dice)
    # Find high score and output
    high_score = find_high_score(dice)
    print("High score:", high_score)

這是回溯 - “回溯(最近一次調用最后一次):文件“main.py”,第 83 行,in dice = [int(val) for val in input().split()] EOFError: EOF when reading a線”

我有點不知所措,所以請幫助我猜測這可能是一個 raw_input() 函數,這就是為什么我的代碼無法正常工作的原因。 請查看上面的鏈接,因為它包含更多信息也是 python 的初學者,所以請用簡單的語言解釋。 謝謝你

此代碼存在一些問題。 首先是沒有調用 find_high_score 函數。 此外,代碼中的任何地方都沒有定義 find_high_score 函數。 這意味着代碼在嘗試調用該函數時將拋出名稱錯誤。

另一個問題是代碼讀取用戶輸入但不以任何方式驗證它。 如果用戶輸入的數字少於五個,或者輸入的數字無效(例如,如果它們是負數或大於 6),代碼也會拋出錯誤。

要解決這些問題,您必須添加 find_high_score 函數定義並在代碼中正確調用它。 此外,您必須驗證輸入以確保用戶恰好輸入了五個有效數字。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM