holding a function to the code in python 1

holding a function to the code in python

def hello():
  name = str(input("Enter your name: "))
  if name:
    print ("Hello " + str(name))
  else:
    print("Hello World") 
  return 
  
hello()

Here is what the above code is Doing:
1. We define a function called hello()
2. We ask the user to enter their name
3. We check if the user has entered a name or not
4. If the user has entered a name, we print “Hello
5. If the user has not entered a name, we print “Hello World”
6. We return from the function

Similar Posts