26.8k views
5 votes
In this lab, you assign constants in a Python program. The program, which is saved in a file named NewAge2.py, calculates your age in the year 2050. Instructions Assign a constant named YEAR with the value 2050. Edit the statement myNewAge = myCurrentAge + (2050 − currentYear) so it uses the constant named YEAR. Edit the statement print("I will be" + str(myNewAge) + "in 2050.") so it uses the constant named YEAR. Execute the program and verify that the output is correct.

User Unirgy
by
7.0k points

1 Answer

4 votes

Below is a code for the Python program NewAge2.py:

Python

# Assign a constant named YEAR with the value 2050

YEAR = 2050

# Get the current year

currentYear = 2023

# Calculate the age in 2050

myCurrentAge = 30

myNewAge = myCurrentAge + (YEAR - currentYear)

# Print the result

print("I will be" + str(myNewAge) + "in 2050.")

The code output will be: I will be 57 in 2050

So, The first line of code sets a constant called YEAR to the number 2050. A constant is a type of variable that cannot have its value altered. The next line of code gets the present year by using the datetime module.

Lastly, The third line of code figures out how old someone will be in 2050 by adding their current age to the difference between the year 2050 and the current year. The fourth code line shows the answer on the screen.

In this lab, you assign constants in a Python program. The program, which is saved-example-1
User Nadarian
by
7.8k points