Python Forum
Not sure how to fix this loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not sure how to fix this loop
#3
In error you get, is an information, that you tried to give "d" in a command line, and convert it to an integer. That, of course, can't work. Maybe would be some idea to make some small check what you get in raw_input. You can do it using "isdigit" method. as you can see below, it returns true when they are only numbers in the string. Btw. you should think about checking the length of "length" because some truly huge number can crash your code.

x = '123'

x.isdigit()
True

y = 'as'

y.isdigit()
False

xyz = '1.123'

xyz.isdigit()
False

xneg = '-5'

xneg.isdigit()
False
Reply


Messages In This Thread
Not sure how to fix this loop - by TheFunkyKoala - May-09-2018, 05:45 AM
RE: Not sure how to fix this loop - by j.crater - May-09-2018, 06:12 AM
RE: Not sure how to fix this loop - by striver - May-09-2018, 06:55 AM

Forum Jump:

User Panel Messages

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