Question 3)
Write a program in Python 3 to print the name of the user as input.
or
Write a Python Program to take the user name as input using input() function and print it in the console.
Code Example:
# Program 3
# Print user name as input
# 1000+ Python Programs by Code2care.org
user_name = input("Hello! Enter your name: ")
print(f"Hello, {user_name}!")
Output:
Hello! Enter your name: Mike Alan
Hello, Mike Alan!
Explanation:
We have made use of two functions here,
- input() - an inbuild function in Python 3 - read more...
- print(prompt) - an inbuild function again, with the prompt string that is printed out to the standard output without a trailing newline - read more...
The user name is saved in the variable user_name and printed using the print function with Literal String Interpolation, also know as as f-strings
Do read more on f-strings: https://code2care.org/python/python-f-string-formatted-string-literals-syntax-and-examples
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org