Python Forum

Full Version: Functions with parameters
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

How would you write a function which takes two parameters and then counts from the first parameter to the second one?

def count(numOne, numTwo):
for i in range ():
print i


count(,)

I'm not sure if I need for over here.

thanks in advance for any advice
The key is that:

range(start, stop)
goes from start to stop - 1.
def count(numOne, numTwo):
for i in range (numOne,numTwo):
print i


print count(5,16)

this would print out what I need (numbers between 5-15) but I'm still getting this error message:

Your function doesn't count to the second parameter - it stops one number short. The Python range keyword is not inclusive - you'll need to add one onto the second parameter.

for i in range (numOne,numTwo+1):
found the solution :)

for i in range (numOne,numTwo+1):
is working