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

-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author Info:

Rakesh (He/Him) is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. 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

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap