Using Python 3 code

Your program should do the following:

Ask the user for their first name
Say “Hello” followed by the user’s first name
Ask the user how old they are
Tell the user how old they will be in 10 years and in 20 years
Tell the user how old they were 5 years ago

1 answer

Here’s a simple Python program that meets your requirements. It will ask the user for their first name and age, then calculate and display their age in 10 years, 20 years, and how old they were 5 years ago.

def main():
    # Ask the user for their first name
    first_name = input("What is your first name? ")
    
    # Say hello to the user
    print(f"Hello, {first_name}!")
    
    # Ask the user how old they are
    age = int(input("How old are you? "))
    
    # Calculate ages in the future and past
    age_in_10_years = age + 10
    age_in_20_years = age + 20
    age_5_years_ago = age - 5
    
    # Print the age results
    print(f"In 10 years, you will be {age_in_10_years} years old.")
    print(f"In 20 years, you will be {age_in_20_years} years old.")
    print(f"5 years ago, you were {age_5_years_ago} years old.")

# Call the main function
if __name__ == "__main__":
    main()

How to Run the Program

  1. Copy the code into a Python file (e.g., age_calculator.py).
  2. Run the program using Python 3 (e.g., python age_calculator.py).
  3. Follow the prompts in the terminal/command prompt.

This program will efficiently gather the user's first name and age, calculate the specified future and past ages, and display the results accordingly.