This code is a simple Python program that interacts with...
This code is a simple Python program that interacts with the user to collect their name and age, then displays a personalized greeting and performs a small calculation. Here's what it does step by step:
-
Ask for the user's name: It prompts the user to enter their name using the input function and stores the result as a string in the variable
name
. -
Ask for the user's age: It prompts the user to enter their age, converts the response to an integer (using
int()
), and stores it in the variableage
. -
Print a greeting: It prints a personalized greeting message, incorporating both the
name
andage
variables using an f-string. -
Perform a calculation: It calculates the user's age for the following year by adding 1 to the
age
variable and stores the result innext_year
. -
Print the result of the calculation: It informs the user of their age in the next year by displaying the value of
next_year
in another personalized message using an f-string.
Example input/output:
What is your name? Alice
How old are you? 25
Hello, Alice! You are 25 years old.
Next year, you will be 26 years old.