Calculating Years - Python Programming Exercise

In this exercise, you will develop a Python program to prompt the user for their age (e.g., 20) and respond with a message like "You look younger than age". The age entered by the user should be displayed in place of "20". This task teaches you how to handle user input and use string concatenation or formatting to insert dynamic values into a message. By completing this exercise, you will improve your understanding of Python syntax and the use of variables to store and display user input. This is a valuable skill for creating interactive Python programs that respond to user input in a personalized way. Understanding these basic concepts will serve as a foundation for more advanced programming tasks in Python.

 Category

Your First Steps in Python

 Exercise

Calculating Years

 Objective

Develop a Python program to prompt the user for their age (e.g., 20) and respond with a message like "You look younger than 20" (the age entered by the user should be displayed in place of "20").

 Example Python Exercise

 Copy Python Code
# Prompt the user to enter their age
age = int(input("Please enter your age: "))

# Display a message with the user's age
print(f"You look younger than {age}")

 Output

Please enter your age: 20
You look younger than 20

 Share this Python Exercise

 More Python Programming Exercises of Your First Steps in Python

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Data Presentation Styles

    In this exercise, you will develop a Python program to prompt the user for a number and display it four times in a row, separated by spaces, and then four time...

  •  Quadrilateral Dimensions

    In this exercise, you will develop a Python program to prompt the user for a number and then display a rectangle 3 columns wide and 5 rows tall using that d...

  •  Conversion

    In this exercise, you will develop a Python program that asks the user for a temperature in Celsius and converts it to both Kelvin and Fahrenheit...

  •  Initial interaction with Python

    In this exercise, you will develop a Python program to output "Hello" on the screen, followed by your name on a separate line. This exercise is perfect for pra...

  •  Addition of two values

    In this exercise, you will develop a Python program to print the result of adding 12 and 13 on the screen. This exercise is perfect for practicing basic arithm...

  •  Divide two values

    In this exercise, you will develop a Python program to display the result of dividing 24 by 5 on the screen. This exercise is perfect for practicing basic arit...