DEV Community

Cover image for How To Make A Random Greeting Giver In Python
Abhishek Hari
Abhishek Hari

Posted on

5 1

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!

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
Enter fullscreen mode Exit fullscreen mode

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']
Enter fullscreen mode Exit fullscreen mode

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!"]
Enter fullscreen mode Exit fullscreen mode

Making An Input

Now we make an input for the user to enter their name.

name = input("> What's your name? ")
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

For The Well-Wish

value2 = random.choice(hope)
Enter fullscreen mode Exit fullscreen mode

Creating A Function

Now we create a function. This will greet the user!

def greet_user():
    print('' + value + ', ' + name + '! ')
    print('' + value2)
Enter fullscreen mode Exit fullscreen mode

Finally...

...we call the function!

greet_user()
Enter fullscreen mode Exit fullscreen mode

That's it, you have successfully created a Random Greeting Giver!
Here's the final product:
Finished Product

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more