45
How To Make A Random Greeting Giver In Python
In this little project, I will show you how to make random greeting giver! You input a name, and it gives you a random greeting, and well-wishes you!
This article will include:
- Random Module
- Lists
- Variables
- And Functions
Let's get coding then!
For this, we will need the random
module. It allows us to make a random pick. You need to import it by writing:
import random
The Random module has been imported!
Now we make two lists, one for greeting them and one for well-wishing them.
greeting = ['Hello', 'Sup', 'Howdy', 'Hi', 'Hola', 'Greetings', 'Namaste']
hope = ["Hope you're having a great week!", "Hope you're having a great day!", "Hope you're doing well!", "Hope you're doing good!"]
Now we make an input for the user to enter their name.
name = input("> What's your name? ")
Now we use random.choice
, which as it sounds makes a random choice. There will be two of them, one for the greeting and one for a well-wish.
value = random.choice(greeting)
value2 = random.choice(hope)
Now we create a function. This will greet the user!
def greet_user():
print('β― ' + value + ', ' + name + '! ')
print('β―' + value2)
...we call the function!
greet_user()
45