Class 4 – Wednesday, September 4
Variation on a theme
A variable — Is like a box or a name — We must all know this
That Black Lives Matter — Should be so easy to grasp — People are people
Look both ways
Downloads
Just report it
- All UVA faculty and administrator, including myself, are committed to creating a safe and equitable environment on grounds. If you experience or observe an instance of sexual harassment, gender-based harassment, violence, bias or discrimination, hazing, or interference with free speech, just report it! If you see a minor being placed at risk, just report it! It’s easy – just go to justreportit.virginia.edu. If you’re unsure if what you’re seeing or experiencing qualifies as something you should report, or if it doesn’t seem to quite match the descriptions on that web site, just report it anyway. The staff who review these reports will follow up with you to assist or to provide referrals in order to ensure your safety or the safety of others.
In-class comportment
- If you see that your neighbor is having difficulty with the current task, please ask if you can help
- If you are having difficulty, please ask your neighbor for advice.
- If more is needed, please raise your hand so that the Teaching Assistant can work with you.
- Do not let things stay muddy, you are paying tuition — make use of the assistance that we can provide.
Agenda
- Further expand our communication skills
- Consider abstraction
- Expand our understanding of variables
- Introduce assignment
- Introduce input acquisition
Important questions
- What is a variable?
- Why is assignment so important
- Does the old value of a variable hang around for us to use?
Problems of the day
What the solution offers
- Basic understanding of variables and assignment.
Check out
What the solution offers
- The ability to update is crucial when problem solving.
What the solution offers
- Examines some nuances of the assignment operator.
- The final version of the program updates the value of variables in terms of themselves; ie., number of rabbits doubles each generation and the generation number is an increment of the previous generation value.
Problem
- Prompt and get a word of interest from user user
- Compute the length of the word
- Output a message about the length of the word
What the solution offers
- Introduces built-in function
input()
. When the function is invoked, its argument is printed to the display, the entry supplied by the user in response to that message is the value of the invocation. Theinput()
function always returns the user reply as a string.
- The
input()
function allows programs to be interactive; i.e., their actions can be influenced by the user. Theinput()
function enables Python to do general problem solving.
Three possible program runs
Tell me a favorite word: rhythms
Did you know that rhythms has length 7
Tell me a favorite word: strengths
Did you know that strengths has length 9
Tell me a favorite word: squirreled
Did you know that squirreled has length 10
Problem
- Prompt and get what is on the user’s mind
- Prompt and get why the first reply is on their mind.
- Print an out of time message
What the solution offers
- Introduces the
str
type operator+
. The+
operator when evaluated with two strings as its operands, produces as its value, their concatenation.
- Another use of the built-in function
input()
.
- Creates and uses an input prompt that makes use of a prior input.
Three possible program runs
Tell me what is on your mind: I worry about the future
Hmmm. Why is -- I worry about the future -- on your mind: Because it it coming
Oh? I wish we had more time to chat. So long.
Tell me what is on your mind: A fluttering butterfly
Hmmm. Why is -- A fluttering butterfly -- on your mind: I do not want rain
Oh? I wish we had more time to chat. So long.
Tell me what is on your mind: Is superman colorblind
Hmmm. Why is -- Is superman colorblind -- on your mind: To account for fashion sense
Oh? I wish we had more time to chat. So long.
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
To do list
- Review class artifacts
- Ensure familarity with Python variables, assignment, and input
- If not already done so, complete and submit the current assignment
- Read, but do not do, the next assignment
© 2019 Jim Cohoon | Resources from previous semesters are available. |