0

I'm new in programming. I was doing this exercise: Write a function called showNumbers that takes a parameter called limit. It should print all the numbers between 0 and limit with a label to identify the even and odd numbers. My solution is this one:

def showNumbers(limit):
  num = 0
  while num <= limit:
    if num % 2 == 0:
      print(f'{num} EVEN')
    else:
      print(f'{num} ODD')
    num += 1

It's returning everything correct but it's also returning a None in the end. How can I remove it?

  • This is because you have not used the `return` keyword. Use the return keyword at the end of the function to return the value that you want when the function will be called. – techytushar Nov 22 '19 at 16:32
  • What dou want to return? – Yeganeh Salami Nov 22 '19 at 16:32
  • 1
    It *prints* the correct output. It *returns* `None`. Ever function returns *something*; without an explicit `return` statement, it will return `None`. There's nothing to fix here. – chepner Nov 22 '19 at 16:33
  • Instead of print you can use return num in two if statements , and add `sum+=1` in above of each return – Yeganeh Salami Nov 22 '19 at 16:37

0 Answers0