A Python program to ask the user to enter name
Here I am going to explain a Python program to ask the user to enter a name. The task is going to be a very easy one. I will explain to you about the commands used in this program and how to write this program using a function.
A simple program to ask for the name in Python
NAME=str(input("enter the name: ")) print("hello",NAME)
output
enter the name: user hello user
The general description of this program is to ask a user name and save the data in “NAME” and to print the name using the variable where the data is stored.”NAME” is just a variable where the data is stored. Since we are asking name where no numbers are allowed so I am using string data type.
Ask the user to enter name in Python using a function
Let’s create our simple custom Python function and then call it:
def hello(): name=str(input("enter the name : ")) print("hello " + str(name)) return hello()
Run this code online
And the output will be like you can see below:
enter the name : user hello user
Here I had altered the general program by using a function. The hello() is a user-defined function used in this program and the function generated in a custom way. In this function, it is programmed to get the user name and to print the user name with a string “hello”.
So you can see that the same functionality is done by defining our own function.
conclusion
I hope that I had demonstrated the program using function and in a simple way for your understanding.
Also read:
Easy to understand
you are doing great,make most of it da
didn’t work i done this before i done this in php and shell not with this exact line of code but similar, mostly.
Thanks so much your website has helped my research a lot
Write a function hello(lastname, firstname ), in the sense if called with hello(‘Adam’,
‘Cloud’), will print two lines:
Hey Cloud Adam
Hey Adam Cloud
fname=str(input(“enter first name: “))
lname=str(input(“enter lastname: “))
print(“Hey”, fname, “”, lname,)
print(“Hey”, lname, “”, fname,)