Python Forum
While loop within a Function (2.7)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop within a Function (2.7)
#2
Since you are in the learning stage, It would be a good idea to buy another book that uses python 3
As far as your code is concerned, your statement
stop = raw_input("How high should we count? ")
inputs a string, not an integer, so when you use the statement
While i < stop:
you are trying to compare an int to a string.

there are other issues, not checking validity of input value, etc. but another issue.
change your input statement to read:
stop = int(raw_input("How high should we count? "))
Again, you will need assert that the input is capable of integer conversion.
Sooner or later someone will enter non valid input and blow the program up
Reply


Messages In This Thread
While loop within a Function (2.7) - by tuffgong - Jun-28-2017, 03:44 PM
RE: While loop within a Function (2.7) - by Larz60+ - Jun-28-2017, 04:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I run a function inside a loop every 24 values of the loop iteration range? mcva 1 2,246 Sep-18-2019, 04:50 PM
Last Post: buran

Forum Jump:

User Panel Messages

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