This is a simple Python program that demonstrates how to create a custom function and get input from the user to process the output. This program allows the user to enter their name, and the program will say hello to the user.
Program
Output
Line 2 – 6
Defining the function hello()
that has a default parameter to = world
which is, to
variable is equal to world
string . In line 3 the program will print hello,
with the variable to
, which by default equals to world
string. The function will execute only if the function call hello()
is exist in line 6.
Line 10 – 13
In line 10 getting user input and with the question “what is your name?” and store that input in a variable called name
. Along with the input function there are two string methods which are strip()
and title()
, by strip()
string method the spaces that user enters when typing the input will be removed and store in the name
variable. By title()
string method, capitalize the first letter of users input and store in name
variable. Finally In line 13 hello(name)
function will be called with the name
variable.