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)

Slides:



Advertisements
Similar presentations
Pollution/Cars Pollution and cars... Find out more by carrying on to watch.
Advertisements

Python - Selection Starter
This Week More Types boolean string Modules print statement Writing programs if statement Type boolean.
Order of operators: x ** y x * y, x / y, x // y, x % y x + y, x - y
Whiteboardmaths.com © 2004 All rights reserved
Whitebox Testing Fra: CS Fall Whitebox Testing AKA Structural, Basis Path Test Normally used at unit level Assumes errors at unit level are.
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Scientific Programming for(i=0; i b) { a = func1(c,d,i*10); } else if(a < b) { a = func2(e,f,i*10); } else { a = func3(g,h,i*10);
Calcul mental multiplications et divisions par multiplications par 0,1 0,01 0,001...
Calculate Population Attributable Risk Percent Smoke YesNo Yes No I SM = 84 / 3000 = = 28.0 / 1000 I NS = 87 / 5000 =
General Computer Science for Engineers CISC 106 Lecture 25 Dr. John Cavazos Computer and Information Sciences 04/20/2009.
Recursion. Sum a list of numbers Iterative def sum(L): total = 0 for i in L: total += i return total Recursive def sum(L): if len(L) == 0: return 0 else:
Genome Sciences 373 Genome Informatics Quiz Section 5 April 28, 2015.
Functions.
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
PPT 2. Other things: functions  Can you have a function with no inputs?  Yes: def f( ): return (3 + 4 )  Can you have a function with no outputs? 
Formula? Unit?.  Formula ?  Unit?  Formula?  Unit?
Pollution Earth and Beyond. What is pollution? The contamination of air, water, or soil by substances that are harmful to living organisms.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
Math – What is a Function? 1. 2 input output function.
Productivity. Calculating productivity Total output Total input Chocolate wave factory has 3000 waves 10 workers 300 waves per worker.
Computing Science 1P Large Group Tutorial 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
M May Pythagoras’ Theorem The square on the hypotenuse equals the sum of the squares on the other two sides.
Solve by factoring. x² = - 4 – 5x 2,. Solve by factoring. n² = -30 – 11n -4 and -1.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
Python if.
C PREPROCESSOR. Introduction  It is a program that processes our source program before it is passed to the compiler.  Preprocessor commands (often known.
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Calcul mental 20 secondes par calcul. 5 ème (-8) + (+4) = (-7) + (+2) = 1 er calcul :
Calcul mental 20 secondes par calcul. 5 ème (-9) - (+4) = (-8) - (+2) = 1 er calcul :
ПЕЧЕНЬ 9. Закладка печени в период эмбрионального развития.
Dictionaries Python.
More on conditional statements. Conditionals In some situations the typical if-else statements may become cumbersome Depending on the situation, there.
Production and Productivity. Production Production is the process of transforming inputs into goods and services. We measure production as the total amount.
Module 3.
Project 1 Part E3 Programming PicoScope ---Looping--
Working with Dictionaries
CSc 110, Autumn 2016 Lecture 12: Advanced if/else; Cumulative sum
Using the Slope Formula
Centrality Bias Measure for High Density QR Code Module Recognition
CSc 110, Spring 2018 Lecture 17: while Loops and decomposition
1. Use the quadratic formula to find all real zeros of the second-degree polynomial
مدل زنجیره ای در برنامه های سلامت
Multiple Selections (ELIF Statements)
Practice with loops! What is the output of each function below?
Function Notation “f of x” Input = x Output = f(x) = y.
The Variance How to calculate it.
عنوان مقاله(B Titr 32) Article Title (Times New Roman 30)
Intro to Programming & Algorithm Design
Factoring if/else code
Section 8.4 – Average Value of a Function
Unit 3 Review (Calculator)
Python Basics with Jupyter Notebook
National Central University, Taiwan
CSC1018F: Functional Programming (Tutorial)
General Computer Science for Engineers CISC 106 Lecture 03
EXPLICIT RULES: INPUT-OUTPUT FORMULAS
Hint idea 2 Split into shorter tasks like this.
Objective: To graph square root functions
Calculate 9 x 81 = x 3 3 x 3 x 3 x 3 3 x 3 x 3 x 3 x 3 x 3 x =
Calculate 81 ÷ 3 = 27 3 x 3 x 3 3 x 3 x 3 x 3 ÷ 3 = This could be written as
CSCE 206 Lab Structured Programming in C
Recursion Exercises.
What does this code do? def digitsum(): code goes here def diffsum():
COMPUTING.
Challenge Guide Grade Code Type Slides
Project 1 Part E2 Programming PicoScope ---Defining Functions---
Lecture 6 - Recursion.
Presentation transcript:

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)

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)

#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)

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)

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)

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)

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),_________)

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')