Ask coding questions

← Back to all posts
How do I ask for input?
RBGoat (2)

So, I got a coding book about Python. (Previously I used Scratch.) It said to ask for input, type the following command:

username=input("What is your username?")
print("Hello," username)

That did not work-It just said Syntax error. How do I properly ask for input in Python?

Answered by Coder100 (18057) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18057)

You forgot to use the + operator to combine two strings together!

print("hello!")
username=input("What is your username?")
print("Hello, " + username)

but that isn't very readable, how about using fstrings?

print("hello!")
username=input("What is your username?")
print(f"Hello, {username}")

much better