Class 5 – Friday, September 1
It's all about you
Show understanding — Put it altogether now — Yes you all can do
Look both ways
Examples
Agenda
- Demontrate your own chresthomatics abilities by solving and submiting solutions for the below problems by the end of class (i.e., 3:15).
By the way (BTW)
- Identifiers in Python are written in snake_case
- Cannot use commas in Python to separate digits; e.g., 1,000,000 is not a Python integer (it turns outs its a three-tuple).
General requirements
- Before leaving demonstrate to a classmate or teaching assistant that you have met the problem specifications. Identify those person(s) as part of the header comments for your programs.
- Do not leaver before your checkers have also been checked out by somebody(s).
Problem how_old_will_i_be_in_2060.py
- For a single user-supplied age, tell them how old they will be in 2060. You are to assume that the user will enter an integer character sequence.
Requirements
- Use separate variables for storing the current age, difference in years, and future age.
- Any numeric value display must be from the value of a variable; i.e., there will never be arithmetic calculations within a
print()
statement.
- The displayed future age is to be integer.
Three possible sample runs
- The above section header Three possible samples runs means what it literally says. Each below box shows a different program run; i.e., your program is to perform single age calculation each time it is run.
Enter your age: 19
In 2060 you will be 62
Enter your age: 21
In 2060 you will be 64
Enter your age: 43
In 2060 you will be 86
Suggested code outline
- Prompt user to supply an age
- Convert user reply to integer
- Compute difference in years between 2060 and 2017
- Compute sum of age and difference in years
- Print sum
Program dateable.py
- For a single user-supplied age, tell them how old a person must be to have dating be acceptable according to the following. There is a folk rule that you should only date someone who is at least seven years older than than half your age. For example, an 18 year old needs to date somebody at least 16 year's old ( 7 + ( 18 / 2 ) ).
Requirements
- The dateable age is to be calculated by using the above folk rule.
- Use separate variables for storing the user-supplied and dateable ages.
- Any numeric value display must be from the value of a variable; i.e., there will never be arithmetic calculations within a
print()
statement.
- The displayed dateable age is to be integer.
Three possible sample runs
Enter your age (integer): 19
19 year olds should date somebody who is at least 16 years old
Enter your age (integer): 22
22 year olds should date somebody who is at least 18 years old
Enter your age (integer): 88
88 year olds should date somebody who is at least 51 years old
Suggested code outline
- Prompt user to supply an integer age
- Convert user reply to integer
- Compute minimum age according to dateability formula
- Print the result of the computation
To do list
- Ensure familarity by reading about Python variables, assignment, and input