[Tutor] raw_input into range() function

Bob Gailer bgailer at alum.rpi.edu
Wed Apr 18 20:19:31 CEST 2007


Guba wrote:
> Hello,
>
> I am trying to do the exercises in Michael Dawson's "Absolute Beginner"
> book. In chapter four ("for Loops, Strings, and Tuples") one of the
> challenges is: "Write a program that counts for the user. Let the user
> enter the starting number, the ending number, and the amount by which to
> count."
>
> The code I have come up with so far is further below; basically my
> problem is that I don't know how to feed the range() function with the
> user-input numbers it expects.
>
> Your help is highly appreciated!
>
> Guba
>
>
> # Counting Program
> # 2007-04-18
>
> # Welcoming the player
> print "Hello, let me do some counting for you!"
>
> # Telling the player what to do & assigning that info to variables.
> start_num = int(raw_input("Please give me a starting number. "))
> end_num = int(raw_input("Please give me an ending number. "))
> interval = int(raw_input("By which amount am I to count? "))
So far so good, if the user enters integers for all 3 inputs. All you 
need now is:

print "Counting:"
for i in range(start_num, end_num, interval):
    print i
>
> start_num == 0
> end_num == 1
> interval == 2
These are expressions that compare a variable to a constant. They 
contribute nothing to the program.


-- 
Bob Gailer
510-978-4454



More information about the Tutor mailing list