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!
Random Module
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!
Making A List
Now we make two lists, one for greeting them and one for well-wishing them.
List For Greeting
greeting = ['Hello', 'Sup', 'Howdy', 'Hi', 'Hola', 'Greetings', 'Namaste']
List For Well-Wishing
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!"]
Making An Input
Now we make an input for the user to enter their name.
name = input("> What's your name? ")
Calling The Random Module
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.
For The Greeting
value = random.choice(greeting)
For The Well-Wish
value2 = random.choice(hope)
Creating A Function
Now we create a function. This will greet the user!
def greet_user():
print('❯ ' + value + ', ' + name + '! ')
print('❯' + value2)
Finally...
...we call the function!
greet_user()
That's it, you have successfully created a Random Greeting Giver!
Here's the final product:
Top comments (0)