Home Tutorials Python Programs Say Hello
Say Hello

Say Hello


Topic: Custom Greeting Generator ("Say Hello")

Description: This introductory program prompts the user to input their name and time of day, then processes the inputs to display a personalized, formatted greeting message in the console.

Why: The "Say Hello" program is the modern evolution of the classic "Hello, World!" milestone. It teaches students how to interact with users via the console using input(), store textual data inside variables, and combine strings using clean output formatting methods.


Program Code

Copy and run the following Python code to see the greeting engine in action:

def generate_greeting():
    print("=============================")
    print("   PERSONAL GREETING ENGINE  ")
    print("=============================")
    
    # Step 1: Accept text inputs from the user
    user_name = input("Enter your name: ").strip()
    time_of_day = input("Enter the time of day (e.g., Morning, Afternoon, Evening): ").strip()
    
    # Step 2: Handle fallback case if input is empty
    if not user_name:
        user_name = "Guest"
    if not time_of_day:
        time_of_day = "Day"
        
    # Step 3: Capitalize inputs for professional formatting
    formatted_name = user_name.title()
    formatted_time = time_of_day.capitalize()
    
    # Step 4: Display the custom greeting using string interpolation (f-string)
    print("\n-----------------------------")
    print(f"👋 Good {formatted_time}, {formatted_name}! Welcome back.")
    print("=============================")

# Execute the greeting program
generate_greeting()

Expected Console Output Examples

Example 1 (Standard Complete Input):

=============================
   PERSONAL GREETING ENGINE  
=============================
Enter your name: alex turner
Enter the time of day (e.g., Morning, Afternoon, Evening): evening

-----------------------------
👋 Good Evening, Alex Turner! Welcome back.
=============================

Example 2 (Fallback / Empty Input Profile):

=============================
   PERSONAL GREETING ENGINE  
=============================
Enter your name: 
Enter the time of day (e.g., Morning, Afternoon, Evening): 

-----------------------------
👋 Good Day, Guest! Welcome back.
=============================

Core Syntax & Concept Breakdown

  • String Sanitization (.strip()): This string utility cuts away any accidental spaces a user might press at the beginning or end of their input, keeping the database variables clean.
  • Casing Methods (.title() vs .capitalize()): .title() capitalizes the first letter of *every* word in a string (perfect for full names like "Alex Turner"), whereas .capitalize() only shifts the very first letter of the entire string to uppercase (ideal for single words like "Evening").
  • Presence Evaluation (if not): Checking if not variable tests whether a string is empty (""). If the user inputs nothing, the script catches it and applies a clean placeholder fallback value ("Guest" or "Day") instead of breaking the sentence structure.

🏋️ Test Yourself With Exercises

Take our quiz on Say Hello to test your knowledge.

Browse Quizzes »