Class 4 – Wednesday, January 24

Variation on a theme

A variable — Is like a box or a name — We must all know this


Look both ways


Agenda


Important questions


Examples of the day

What the solution offers

  • Formally introduces the assignment operator =. The assignment operator causes the variable to its left to get the value of the expression to its right.
  • 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 what is on the user’s mind
  • Echo (print) the reply
  • Prompt and get why the first reply is on their mind.
  • Prints ooh

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.
  • Also 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. The input() 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. The input() function enables Python to do general problem solving.
  • The final version of the program reflects echoing of the first input before printing the second prompt

What the solution offers

  • Uses the built-in cast functions int() and float() to convert numeric strings into the numbers they represent.
  • The final version of the program shows the two casts using built-in functions int() and float() to convert the supplied string-based inputs into numerics.

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 a split() invocation is the list of substrings (words) that make up the string being told to split(). 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.


To do list




rabbits galore

 



Warning: fopen(/l/cs1112/public_html/defs/htm/181-trailer): Failed to open stream: No such file or directory in /l/cs1112/public_html/defs/php/read.php on line 5
Unable to open file!