fb pixel

input()

Most real-world applications depend on user inputs and change their execution logic based on those inputs. Their outputs can depend on what the user inputs into the program. So far we’ve only looked at programs that print fixed outputs.
print() is used to print output. input(), on the other hand, is used to get input from the user. The user can enter their name, a phone number, some message, etc.
So, if we would like to write a simple program that would greet the user we should store the user input in some variable and print it later (we will discuss variables in more detail later):
name = input()
print('Hi', name)
Here the program prints the fixed text Hi followed by the value stored in the variable called name. In case the user inputs Anna, the program would print Hi Anna. In case the user inputs Simon, the program would print Hi Simon. So, the same program prints different things depending on what the user inputs.
Note that name is assigned to input(). This tells Python to store the value entered by the user in the variable called name. After that, we are able to print the name like any other text or number. Pay attention that to print the value stored in the variable, we don’t use quotes and instead write the name of the variable.
 

Challenge

Write a program that would greet the user with Hello, and then the name of the user.
Here are some examples of how the program should behave for different inputs:
Input
Output
Anna
Hello, Anna
Bob
Hello, Bob
 
To check your solution you need to sign in
Sign in to continue