Class 26 — Wednesday March 25

Module implementation and usage

Practice makes perfect — Is more than a platitude — Take it to your heart


Look both ways


Agenda


Buddying


Slides


Downloads



To do


Module uva: freestyling

  • Has one integer parameter n, which is the number of credits earned so far.
  • Returns the remaining number of credits needed to graduate.
  • Assumption: CLAS student so 120 credits is amount needed.
  • Has no parameters
  • Returns the number of years since UVA was founded.
  • Not sure want to do this one — sticky wicket
  • Has two parameters numeric parameters score and total, where score is points earned and total is the maximum number of points possible.
  • Returns the percentage grade given score and total. As student-specified, the return should include a % at the end of the percentage. For example, the following code segment

s = 17

t = 20

pct = uva.grade_as_percent( s, t )

print( "grade_as_percent(", s, ",", t, "):", pct )

should print

grade_as_percent( 17, 20 ): 85.0%


Module primal: to be submitted to document your participation

  • The % is the Python remainder operator.
  • Determine remainder of x divided by y
  • By looking at the remainder we can tell whether to return True or False

  • Could is_factor() help?
  • What are the possible range of values do we need check for being possible factors of x.
  • Does the function need a loop?

  • Could is_prime() help?
  • Could is_factor() help?
  • Do we need both of them?
  • Does the function need a loop?


cel from primal cartoon


Slide show

 


 
  © 2020 Jim Cohoon   Resources from previous semesters are available.