Class 5 – Friday, September 6
It's all about you
Show understanding — Put it altogether now — Yes you all can do
Help crush breast cancer — For your friends and families— Not be asunder
Look both ways
Agenda
- Further expand our communication skills
- Introduce objects
- Introduce Python string manipulation capabilities
- Get adept at casting
- Demontrate your own chresthomatics abilities by solving and submiting problem solutions before the end of class.
Galleries
- Nothing but the truth
Enlightening examples
Problem
- Prompt and get an integer number (the base for the computation)
- Prompt and get a decimal number (the exponent for the computation)
- Compute the value of the integer to power of the decimal number
- Print the result of the computation
What the solution offers
- Uses the built-in cast functions
int()
andfloat()
to convert numeric strings into the numbers they represent.
- The final version of the program shows the two casts using built-in functions
int()
andfloat()
to convert the supplied string-based inputs into numerics.
Three possible program runs
Enter base (integer): 2
Enter exponent (decimal): 0.5
1.4142135623730951
Enter base (integer): 11
Enter exponent (decimal): 3.14
1861.971509290233
Enter base (integer): 9
Enter exponent (decimal): 99.9
2.132193882555869e+95
Problem
- Prompt user for three words
- Split the input into separate words
- Print the words on separate lines
What the solution offers
- Introduces the string member function
split()
. Its called a member because every string can be called upon to produce a split up version of itself. The value of asplit()
invocation is the list of substrings (words) that make up the string being told tosplit()
. The function is handy for breaking up user input into its individual parts.
- The final version of the program shows that every string has a member function for inspecting itself. The
split()
function hands back the list of words that make up the string.
Three possible program runs
What are your three favorite words: peace joy friends
peace
joy
friends
What are your three favorite words: you me us
you
me
us
What are your three favorite words: subcontinental billowy uncopyrightable
subcontinental
billowy
uncopyrightable
Problem
- Prompt and input from user both an integer width and height of a rectangle
- Split the input into two strings
- Convert strings into integers
- Compute the product
- Produce the result
What the solution offers
- Shows the proper way of converting the splitting of a string made up of numberic characters into individual numbers.
Three possible program runs
Enter rectangle width and height (integers): 5 6
30
Enter rectangle width and height (integers): 2 71
142
Enter rectangle width and height (integers): 3 14
42
Homework requirements and warning
- A numeric value display must be from the value of a variable; i.e., there will never be arithmetic calculations within a
print()
statement.
- All variables should be named indicating their purpose/usage.
- Always end each prompt with a space; e.g.,
input( 'What is something you consume daily?: ' )
- The testing of your programs will use inputs different from those shown in problem discussion.
In-class homework requirements
- Demonstrate to a classmate that you have met the problem specifications. Identify those person(s) as part of the header comments for your programs.
- Ensure your checkers have also been successfully checked out by somebody(s).
Program complimenter.py
- For a single user-supplied integer age, print out a tasteful compliment based on the supplied age.
-
Requirements
- The faux (complimentary) age is the user-supplied age minus five years.
- The faux age is to be integer.
- The program does not attempt to get more than one input from the user.
-
Three different program runs
- The above section header means what it literally says. The below boxes each show a different program run; i.e., your program is to perform a single age calculation each time it is run.
Enter your age: 19
You don’t even look 14
Enter your age: 111
You don’t even look 106
Enter your age: 20
You don’t even look 15
-
Suggested code outline
- Prompt user to supply an age
- Convert user reply to integer
- Compute supposed age
- Print the result of the computation
To do list
- Check out the the activities for next class
- Ensure familarity of the past by carefully examining artifacts, epistles, and videos.
- Complete homework 06 as soon as possible for your sake.
- Check out the string module. It will be a major topic next week
© 2019 Jim Cohoon | Resources from previous semesters are available. |