Program 3: Print the name of user as input - 1000+ Python Programs


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:

Print User Name as input - Python Program
# 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...
Gif Demo of Program with input function

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

-


Have Questions? Post them here!


Top Hashtags: