Class 5 – Friday, January 24

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


New past example


Un-enlightening example


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() 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.

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.132201+95


Problem

  • Prompt user for three words
  • Split the input into separate words
  • Print the words on separate lines

What the solution offers

  • 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


In-class homework requirements


Program complimenter.py

  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


To do list

 


variables as boxes

 


 
  © 2020 Jim Cohoon   Resources from previous semesters are available.