0

I got an EOFError at line 87 of the following code:

import random
def printDice(diceList):
    upperLine=" _____     _____     _____     _____     _____"
    line1="|" 
    line2="|"
    line3="|"
    lowerLine=" -----    -----    -----    -----    -----"
    for i in range(len(diceList)):
        if(diceList[i]==1):
            line1+="     "
        elif(diceList[i]==2):
            line1+="*    "
        elif(diceList[i]==3):
            line1+="*    "
        elif(diceList[i]==4):
            line1+="*   *"
        elif(diceList[i]==5):
            line1+="*   *"
        else:
            line1+="*   *"
        if(i==4):
            line1+="|"
        else:
            line1+="|  |"
    for i in range(len(diceList)):
        if(diceList[i]==1):
            line2+="  *  "
        elif(diceList[i]==2):
            line2+="     "
        elif(diceList[i]==3):
            line2+="  *  "
        elif(diceList[i]==4):
            line2+="     "
        elif(diceList[i]==5):
            line2+="  *  "
        else:
            line2+="*   *"
        if(i==4):
            line2+="|"
        else:
            line2+="|  |"
    for i in range(len(diceList)):
        if(diceList[i]==1):
            line3+="     "
        elif(diceList[i]==2):
            line3+="    *"
        elif(diceList[i]==3):
            line3+="    *"
        elif(diceList[i]==4):
            line3+="*   *"
        elif(diceList[i]==5):
            line3+="*   *"
        else:
            line3+="*   *"
        if(i==4):
            line3+="|"
        else:
            line3+="|  |"
    print upperLine
    print line1
    print line2
    print line3
    print lowerLine

tellMe="N"
print

print "The purpose of the game is to figure out the rule."
print "I can tell you three things:\n1. The name of the game is petals around a rose,  the name is important.\n2. I can tell you whether or not your guess is right and the score of the dice.\n3. I can tell you that the score is always even or 0"
print
print "At any time you can quit by typing an odd number"
go="Y"
wrongGuesses=0
while(go=="Y"):
    diceList=[]
    score=0
    rightWrong="N"
    for i in range(5):
         diceList.append(random.randrange(1,7))
    for i in range(5):
        if(diceList[i]==3):
            score+=2
        elif(diceList[i]==5):
            score+=4
    printDice(diceList)
    print
    while(rightWrong=="N"):
        guess=input("What is your guess? ")
        if(guess%2==1):
            break
        if(guess!=score):
            print "Wrong"
            wrongGuesses+=1
            tellMe=raw_input("Tell you (Y or N)? ")
            tellMe=tellMe.upper()
            if(tellMe=="Y"):
                print "The score was "+str(score)+"."
                rightWrong="Y"
            else:
                rightWrong="Y"
            print "Right"
    if(wrongGuesses%13==0 and wrongGuesses!=0):
        print"The name is very important."
    if((wrongGuesses==30) and (wrongGuesses!=0)):
        print "The maximum score is 20."
    print

I was using the site codepad.org to run this program. I have actually run this program in an IDE but when I use this site this error pops up:

What is your guess?

Traceback (most recent call last):
  Line 88, in <module>
    guess=input("What is your guess? ")
EOFError
4

3 回答 3

4

Your program reads user input from standard input. When running it on codepad.org, there is no user input and attempting to read from standard input will result in an EOFError.

If you use the site ideone.com instead, it allows you to specify the user input. However, you will have to provide the entire input ahead of time rather than interactively. If your program tries to read past the end of the provided input, you will get EOFError again.

于 2012-05-31T17:15:26.000 回答
0

Assuming you are using Python 2.x, it should be:

raw_input

and not input.

raw_input was changed to input in Python 3.x

于 2012-05-31T17:09:29.070 回答
0

Technically it is not an error, rather an exception. This exception is raised when one of the built-in function, most commonly

input()

returns End-Of-File(EOF) without reading any data. Sometimes all our program tries to do is to fetch something and modify it. But when it is unable to fetch, it will raise this exception.

于 2018-10-17T05:43:25.080 回答