0

My code seems to be printing a None at the end of the code. I read that it is due to several print statements, but I'm not sure how to fix it in my case:

def type(str):
    for char in str:
        sys.stdout.write(char)
        sys.stdout.flush()
        time.sleep(0.075)
    time.sleep(1.5)

input1 = input(type("""\na. You go to the printer
b. Go to keyboard"""))

output:

a. You go to the printer
b. Go to keyboardNone

How can I get rid of the extra None in the end?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
AmeFyst_
  • 1
  • 3

1 Answers1

1

type here returns None, which is fed to input, which will then write it after type has finished execution, so, first, I would recommend changing the name of the function type to something else, because type is a built-in Python function, and by defining your own, you're shadowing the original, second, you could call type before asking for input:

type("""\na. You go to the printer
b. Go to keyboard""")

input1 = input()

The note about type can also be said of the parameter name str of type, str is also a built-in Python function, and using it as a parameter name will shadow the built-in function but only in the scope of the function in which it is defined (type), so I would recommend changing that too.

DjaouadNM
  • 22,013
  • 4
  • 33
  • 55