![](/img/trans.png)
[英]I get an EOFError because of an input() I have in my Python program. I don't even know why I have it. How should I fix it?
[英]I got An EOFError while doing a project and I don't know how to fix it
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.