Python Forum
Trivia2 Loop problem?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trivia2 Loop problem?
#4
Well, you didn't use any of the suggestions nilamo gave. You need to cast it as an int in order to add it to another int, you just need to handle cases where it isn't an int. Any easy way to do this is with isdigit:

>>> '32'.isdigit()
True
>>> 'Five'.isdigit()
False
>>> ''.isdigit()
False
You can use this to detect a string containing an integer. Use an if statement to cast and add if it's an int, and to skip to the next line if it isn't. Or take either of nilamo's other two suggestions.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
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,722 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