1

I'm trying to use the input function but every time, without fail, the word "None" appears at the end of my question/string (well running), it's capitalized just like that but has no overall effect on the code, it just ruins the project I'm working on.

Here's my code:

import time
import sys
def dp(s):
    for c in s:
        if c != " ":
            sys.stdout.write(c)
            sys.stdout.flush()
            time.sleep(0.22)
        elif c == " ":
            sys.stdout.write(c)
            sys.stdout.flush()
            time.sleep(0)

name = input(dp("Hello, whats your name? "))
David Buck
  • 3,752
  • 35
  • 31
  • 35
Evan2803
  • 11
  • 2
  • Does this answer your question? [Why is "None" printed after my function's output?](https://stackoverflow.com/questions/7053652/why-is-none-printed-after-my-functions-output) – David Buck Oct 19 '22 at 18:49

1 Answers1

2

Every function in python will return something, and if that something isn't defined it will be None (you can also explicitly return None in a function). So, your dp() function returns None, and so you are effectively calling input(None), which gives the same prompt of None.

Instead, try putting in input() call within the function itself.

def dp(s):
    for c in s:
        if c != " ":
            sys.stdout.write(c)
            sys.stdout.flush()
            time.sleep(0.22)
        elif c == " ":
            sys.stdout.write(c)
            sys.stdout.flush()
            time.sleep(0)
    return input()

name = dp("Hello, whats your name? ")
scotscotmcc
  • 2,719
  • 1
  • 6
  • 29