Python Forum
Functions with parameters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Functions with parameters
#1
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
Reply
#2
The key is that:

range(start, stop)
goes from start to stop - 1.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Functions & Passing Parameters KAShears79 3 1,681 Jan-17-2021, 08:28 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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