Monday 22 January 2024

Read username and welcome user in Python

We can read the input from user using ‘input’ function.


my_name = input()

 

Once we read the usename, we can print it to the console using print() function.

print('Very nice to meet you ' + my_name + ", Have a Good Day....")

read_input_and_welcome_user.py

print('Hello, What is your name?')
my_name = input()

print('Very nice to meet you ' + my_name + ", Have a Good Day....")

Output

Hello, What is your name?
Krishna
Very nice to meet you Krishna, Have a Good Day....

Here's a breakdown of what each part of the program does:

 

print('Hello, What is your name?')

This line outputs the text "Hello, What is your name?" to the console. It's a way of prompting the user to input their name.

 

my_name = input()

This line waits for the user to input something and then presses Enter. Whatever the user types is then stored as a string in the variable my_name. The input() function in Python is used to get input from the user.

 

print('Very nice to meet you ' + my_name + ", Have a Good Day....")

This line constructs a new string and sends it to the console. It does this by concatenating (joining together) several strings.



Previous                                                 Next                                                 Home

No comments:

Post a Comment