Class 7 – Wednesday, January 29
Make Bill Murray proud
Take another step — Chrestomathics awaits you — Feel the momentum
All Hoos got your back — A single community — In it together
Look both ways
Survey
Is a rose by any other name still a rose
Agenda
- Continues introduction to the string type
str
- Changes the past
- 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 combine_multiply.py
- Program lickety_strip_and_split.py
- Program subscripting.py
- Program love_is_all_you_need.py
- Program break_the_bank.py
Office hours
Times TBD
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
Program subscripting.py
- Explores selecting an individual character from a string — subscripting
- Introduces indexes.
Program output
### [] is the string index operator
s = obliviator
0123456789
n = len( s ) = 10
### If the [] operand is an integer value, it is subscripting
s[ 0 ] = o
s[ 4 ] = v
s[ n-1 ] = r
Program love_is_all_you_need.py
- Prints the adage Love is all you need the requested number of times
Some program runs
Enter number of lines to be printed: 5
Love is all you need
Love is all you need
Love is all you need
Love is all you need
Love is all you need
Enter number of lines to be printed: 1
Love is all you need
Enter number of lines to be printed: 0
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 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, consider the built-in
round()
function.
© 2020 Jim Cohoon | Resources from previous semesters are available. |