Class 25 — Friday October 26

Reaching an understanding with functions

Functional living — Problem-solving strategy — Embrace this future


Look both ways


Agenda


Last chance


Downloads



To do


Example de jeur — module primal

  • Parameters x and y are integers. The function returns whether y is a factor of x.

Observations

  • y is a factor of x, if the remainder of x divided by y is zero.
  • The % is the Python remainder operator.

Possible algorithm

  • Determine remainder of x divided by y
  • By looking at the remainder we can tell whether to return True or False

  • Parameter x is an integer. The function returns whether x is prime; i.e., its only factors are 1 and itself

Question

  • Could is_factor() help?

  • Parameters x and y are integers. The function returns whether x and y are relatively prime; i.e., whether y is not a factor of x and vice-versa.

Questions

  • Could is_prime() help?
  • Could is_factor() help?


cel from primal cartoon

 


 

 

 
   
   
   
 
  © 2019 Jim Cohoon   Resources from previous semesters are available.