-1

I'm trying to create a function that uses a while loop to count up from one to a number given by a user. The code executes as I intend it to but returns None at the end. How do I get rid of the None? Here's the code.

def printFunction(n):
    i = 1
    while i <= n:
        print(i)
        i+=1


print (printFunction(int(input())))
jonrsharpe
  • 107,083
  • 22
  • 201
  • 376

1 Answers1

1

You can use this code to prevent none, tough its just the last line changed

def printFunction(n):
i = 1
while i <= n:
    print(i)
    i+=1
printFunction(int(input()))

In the last line you were using print(printFunction(int(input()))) which was getting you None after printing the results.

Instead just use printFunction(int(input())). This will not print None. You can also use a message to ask user like printFunction(int(input("Enter a number"))). Since there is noting getting returned you no need to use print.

tobias_k
  • 78,071
  • 11
  • 109
  • 168
Chetan_Vasudevan
  • 2,354
  • 1
  • 11
  • 32