ConDosZ
ConDosZ

Reputation: 1

'None' appears out of nowhere in my code

print("text")
print("text")
name=str(input("text"))
name=name.capitalize()
tutorial=str(input(print(name,"do you know the rules? (YES/NO)",sep=", ")))
tutorial=tutorial.upper()

I can't find the error in my code. Everytime I run it a "None" keeps coming out of nowhere. (replaced some parts of the code so it can be read more easily)

Name? >>>HAL 9000
Hal 9000, do you know the rules? (YES/NO)
None #This I want to erase

Upvotes: 0

Views: 194

Answers (2)

idjaw
idjaw

Reputation: 26570

Your problem is in this line:

tutorial=str(input(print(name,"do you know the rules? (YES/NO)",sep=", ")))

You are getting that None because you have an unnecessary print inside your input. Your input is using the return of that print, which does not return anything, so by default is None. You are still seeing what is inside print because of the obvious functionality of print to output what you are sending inside the print method.

View this example that replicates your problem:

>>> input(print('bob'))
bob
None
''
>>>

To fix this problem, remove that print. Also, change the string in your input to use string format:

tutorial=str(input("{} do you know the rules? (YES/NO)".format(name)))

Upvotes: 1

Amber
Amber

Reputation: 526533

print doesn't return a value, so it's treated as returning None. Which means that you're effectively calling input(None) which prints out "None" before prompting you for input.

Upvotes: 0

Related Questions