>>> input('Enter your name: ')
Enter your name: Jon
'Jon'
Write a Python script that prints some information provided by a user.
Background
In addition to information about type conversions in Lecture 6, you will need
to know about Python’s input()
function to complete this assignment.
input()
can be used to ask the user a question; the function call evaluates
to whatever the user responds with.
For example, calling input('Enter your name: ')
will prompt the user to
enter their name; the result of this function call will be whatever name the
user typed in.
This example is shown below:
Objective
Your goal for this assignment is to write a Python script that will:
-
prompt the user for their name
-
prompt the user for their age
-
print a string telling the user how old they will be on this date in 2030
For example, if I enter the name Jonathan
and the age 40
, the script
should print exactly the following string:
Jonathan will be 46 in 2030.
Procedure
-
As always, start by asking yourself, how would I solve this problem by hand? Work through a couple of examples on paper and note the way in which you solve the problem.
-
Write some pseudocode to describe the steps that are required to prompt the user for input, store information and perform any necessary calculations.
-
Convert your pseudocode into a Python script. Choose helpful, descriptive variable names and use comments to explain any unintuitive parts to your peers (who will be reviewing your assignment). Do not include your name or student number in your script.
-
Finally, submit the result as a file called
exercise2.py
to Gradescope for functional evaluation.