Download presentation

Presentation is loading. Please wait.

Published byAugustus Chunn Modified about 1 year ago

1
Code: from cisc106 import * def myfunc(value1,value2): return (value1 + value2) assertEqual(myfunc(3,2),5) assertEqual(myfunc(7,4),11) assertEqual(myfunc(9,8),17)

2
Code: from cisc106 import * def newfunc(par1): return(par1**par1) def newfunc2(par1,par2): return (par1 % par2) def newfunc3(par1, par2, par3): return(par1+(par2/par3)) assertEqual(newfunc(3),27) assertEqual(newfunc(5),3125) assertEqual(newfunc(2),4) assertEqual(newfunc2(5,3),2) assertEqual(newfunc2(18,6),0) assertEqual(newfunc2(7,2),1) assertEqual(newfunc3(3,4,2),5) assertEqual(newfunc3(7,6,2),10) assertEqual(newfunc3(4,21,7),7)

3
#This function calculates the square of the input value #and returns that squared value #input: a number #output: a number #Test Cases: # assertEqual(newfunc(3),27) # assertEqual(newfunc(5),3125) # assertEqual(newfunc(2),4) #Author: Debra Yarrington #Sept 6, 2011 def newfunc(par1): return(par1**par1)

4
from cisc106 import * # This function calculates a rating of how healthy your state is based on #the % of people who are a healthy weight(w), the % of the state that is #park land (pl), the % of pollutant particles (pp) in the air, and the # % of people who smoke (s) using the formula: # (w *.25) + (pl *.25) + ((100 – pp)*.20) + ((100 – s) *.30) # #Input: 4 numbers #Output: A number def StateHealth(w,pl,pp,s): return((w *.25) + (pl *.25) + ((100 - pp) *.20) + ((100 - s) *.30)) assertEqual(StateHealth(80,73,18,19),78.95) assertEqual(StateHealth(57,96,55,16),72.45) assertEqual(StateHealth(100,100, 0, 0),100.0)

5
def StateHealth(w,pl,pp,s): return((w *.25) + (pl *.25) + ((100 - pp) *.20) + ((100 - s) *.30)) def AreaHealth2(w1,pl1,pp1,s1,w2,pl2,pp2,s2,w3,pl3,pp3,s3,w4,pl4,pp4,s4): return ((StateHealth(w1,pl1,pp1,s1) + StateHealth(w2,pl2,pp2,s2) + StateHealth(w3,pl3,pp3,s3) + StateHealth(w4,pl4,pp4,s4))/ 4.0)

6
def f1(par1, par2): return(par2 - par1) assertEqual(f1(2,4),2) def f2(x1,x2): return(x1**2 + x2) assertEqual(f2(3,6),15) def f3(p1,p2): return(f2(p1,p2) + f1(p1,p2)) assertEqual(f3(3,2), ____) assertEqual(f3(3,2), 10) def f4(p1,p2): return(f2(p2,p2) - f1(p1,p1)) assertEqual(f4(4,2),____) assertEqual(f4(4,2),6) def f5(q1,q2): return(f2(q2,q1)) assertEqual(f5(17,5),____) assertEqual(f5(17,5),42) def f6(par1,par2): return( 3 + f1(par1, 17+par1)) assertEqual(f6(4,26),_____) assertEqual(f6(4,26),20)

7
Given the function def Squr(par1): return(par1 ** 2) def dbl(par2): return(par2 + par2) What does this get us? def Func1(p1,p2): return(Squr(p1) - Squr(p2)) assertEqual(Func1(4,3),_______) def Func2(p1,p2,p3): return(Squr(p1) * Func1(p2,p3)) assertEqual(Func2(2,3,2),_________) def Func3(p1,p2): return(dbl(Squr(p1))) assertEqual(Func3(4),_________) def Func4(p1,p2): return(dbl(Squr(p2)+ Squr(p2)+3)) assertEqual(Func4(2,4),_________) def Func5(p1): return(dbl(dbl(dbl(p1)))) assertEqual(Func5(4),_________)

8
from cisc106 import * def StateHealth(w,pl,pp,s): return((w *.25) + (pl *.25) + ((100-pp) *.20) + ((100 - s) *.30)) assertEqual(StateHealth(80,73,18,19),78.95) assertEqual(StateHealth(57,96,55,16),72.45) assertEqual(StateHealth(100,100, 0, 0),100.0) def StateGrade(w,p1,pp,s): if (StateHealth(w,p1,pp,s) > 93): return ("A") elif (StateHealth(w,p1,pp,s) > 84): return('B') elif (StateHealth(w,p1,pp,s) > 75): return('C') elif (StateHealth(w,p1,pp,s) > 66): return('D') else: return('F') assertEqual(StateGrade(80,73,18,19),'C') assertEqual(StateGrade(57,96,55,16),'D') assertEqual(StateGrade(100,100, 0, 0),'A')

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google