Class 7 – Wednesday, September 11
Make Bill Murray proud
Take another step — Chrestomathics awaits you — Feel the momentum
Look both ways
Agenda
- Continue exploration of the basics of problem solving — getting data, performing computation, and displaying information. Along the way we will develop an appreciation for expression evaluation and formulation
Downloads
- Program temperature.py
- Program drops.py
- Program whats_the_point.py
- Program break_the_bank.py
Survey
Office hours
Monday | Tuesday | Wednesday | Thursday | Friday |
12:00-14:00 R. Green | 17:00-19:00 B. Nielsen | 15:30-17:30 S. Rogers | 16:00-18:00 N. Hassan | 09:00-11:00 A. Hoang |
16:30-18:30 R. McNamara | 18:00-20:00 J. Seaman | 10:00-12:00 H. Khoung | ||
14:30-16:30 V. Donnelly |
Location Thornton A Stacks
To do list
- Review class artifacts
- Finish homework
- Check out other Python built-in functions
- Reread about Python string capabilities.
- Reread problem-solving epistle
Problem notes
Program temperature.py
- Prompts user for a integer Celsius temperature and separately computes its integer and decimal Fahrenheit equivalent using the formula
- Two different possible runs
Enter Celsius temperature: 24
24 C = 75.2 F
24 C = 75 F
Enter Celsius temperature: 8
8 C = 46.4 F
8 C = 46 F
Program whats_the_point.py
- Prompts user for a decimal value and echoes (displays) the value back showing on separate lines 5, 4, 3, 2, 1, and 0 decimal places of accuracy. It finally displays the number rounded to an integer.
- FYI: there is a built-in Python function
round()
that can take one or two arguments. The first argument is the value to be rounded, the second optional value is the wanted number of places after the decimal. When a second value is not supplied, it rounds to an integer.
- Three different possible runs
Enter number: 3.14159265359
3.14159265359
3.14159
3.1416
3.142
3.14
3.1
3.0
3
Enter number: -3.14159265359
-3.14159265359
-3.14159
-3.1416
-3.142
-3.14
-3.1
-3.0
-3
Enter number: 4.998234
4.998234
4.99823
4.9982
4.998
5.0
5.0
5
5.0
Program drops.py
- Prompts user for an integer number of gallons of interest. The program computes and prints the number of drops of water for the indicated amount. Assume there are 90,922 drops of water per gallon. FYI
- A standard bathtub can hold eighty gallons of water
- The Atlantic Ocean holds about 93701099000000000000000000000 gallons of water
- Three different possible runs
Enter number of gallons(integer): 1
90922
Enter number of gallons(integer): 80
7273760
Enter number of gallons(integer): 93701099000000000000000000000
8519491323278000000000000000000000
Program break_the_bank.py
- With a single prompt, it gets from the user four values in the following order: number of quarters, dimes, nickels, and pennies. Computes and displays how much the coinage is worth.
- Two different possible runs
Number of quarters, dimes, nickels, and pennies: 27 14 28 18
Coinage
27 quarters
14 dimes
28 nickels
18 pennies
are worth 9.73 dollars
Number of quarters, dimes, nickels, and pennies: 1 2 3 4
Coinage
1 quarters
2 dimes
3 nickels
4 pennies
are worth 0.6400000000000001 dollars
- For those who dislike Python's approximation in the second test run, use the built-in
round()
function.
© 2019 Jim Cohoon | Resources from previous semesters are available. |