Name and greet" is a simple Python project that allows the user to input their name and select a type of greeting. Based on their choice, the program outputs a personalized greeting. This project is a great way to get started with Python programming and practicing input/output functionality, if/else statements, and user prompts.
The program can be customized and expanded by adding more greeting options or by making the program more interactive, such as asking the user additional questions or providing them with more choices. With a few modifications, this project can be turned into a more complex chatbot or an interactive user interface for greeting people.
Open your Python development environment (such as IDLE or PyCharm).
Create a new Python file and name it
main.py
.
Start by printing a welcome message to the user:
python
print("Welcome to the name and greet program!")
- Next, prompt the user to enter their name:
name = input("Please enter your name: ")
- Once the user enters their name, prompt them to select a type of greeting:
print(f"Hi {name}! How would you like to be greeted?")
print("1. Say hello")
print("2. Wave")
print("3. Smile")
choice = input("Enter your choice (1/2/3): ")
- Now, based on the user's choice, output a personalized greeting:
if choice == "1":
print(f"Hello {name}, wishing you a pleasant day from here")
elif choice == "2":
print(f"Nice to meet you {name}! Waves")
elif choice == "3":
print(f"It's so nice to meet you with a smile {name}. The Lord is your strength")
else:
print("Invalid choice. Please enter 1, 2 or 3.")
- Finally, print a thank you message to the user:
print("Thanks for using the name and greet program!")
- Save the file and run the program to test it out.
python3 main.py
That's it! This simple program prompts the user to enter their name and then allows them to select a type of greeting. Based on their choice, a personalized greeting is displayed. You can customize the program with additional features or make it more interactive.
- Follow me on twitter Emmanuel Adetoro
- Source code Download source code
Top comments (0)