1

Im new to python and trying to convert input to a list and I am required to use a while loop but I keep getting an EOF error.

def get_grades():
    value = float(input('Enter grade:\n'))
    grades = []
    while value > 0:
        grades.append(value)
        value = float(input('Enter grade:\n'))
    return(get_grades)

1 Answer 1

1

I think you want to return the list of grades from that function, so you could change return(get_grades) to return grades (no need for the parentheses). When you have return(get_grades) you're actually returning the address that the get_grades function is stored at in memory.

So with that change the code looks like:

def get_grades():
    value = float(input('Enter grade:\n'))
    grades = []
    while value > 0:
        grades.append(value)
        value = float(input('Enter grade:\n'))
    return grades

print(get_grades())

You can run it with the following inputs and see those printed out to the console:

Enter grade:
30
Enter grade:
40
Enter grade:
50
Enter grade:
0
[30.0, 40.0, 50.0]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.