List Info

Thread: raw_input into range() function




raw_input into range() function
user name
2007-04-18 05:35:53
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? "))

start_num == 0
end_num == 1
interval == 2

print "Counting:"
for i in range(0, 1, 2):
     print i


raw_input("nnHit Enter to exit.")





	
		
___________________________________________________________

Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen
Yahoo! Mail: http://mail.yahoo.de

_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: raw_input into range() function
user name
2007-04-18 06:00:57
Guba wrote:

> 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.

> # 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? "))
> 
> start_num == 0
> end_num == 1
> interval == 2
> 
> print "Counting:"
> for i in range(0, 1, 2):
>     print i

Just use the variable names instead of the numbers:
   for i in range(start_num, end_num, interval):

Kent
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )