Python Forum
Trivia2 Loop problem?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trivia2 Loop problem?
#2
(Jun-06-2017, 02:08 PM)milll929 Wrote:    points = next_line(the_file)
 
   return category, question, answers, correct, explanation, int(points)

You're reading lines from a file, and converting those lines to an int. Based on the error, it looks like one of the lines is blank.

>>> int("5")
5
>>> int("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: ''
So either get rid of the blank line, or test to see if the line actually has contents before trying to cast it to an int, or use try/except to handle the error.
Reply


Messages In This Thread
Trivia2 Loop problem? - by milll929 - Jun-06-2017, 02:08 PM
RE: Trivia2 Loop problem? - by nilamo - Jun-06-2017, 04:13 PM
RE: Trivia2 Loop problem? - by milll929 - Jun-06-2017, 11:27 PM
RE: Trivia2 Loop problem? - by ichabod801 - Jun-07-2017, 12:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with for loop Intellectual11 5 2,760 Aug-26-2021, 04:14 PM
Last Post: naughtyCat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020