• Tidak ada hasil yang ditemukan

Chapter 8 Function

N/A
N/A
Protected

Academic year: 2024

Membagikan "Chapter 8 Function"

Copied!
1
0
0

Teks penuh

(1)

Chapter 8 Function

The first example in the slide:

mean median mode

they are "average" in different senses.

mean is averaging the values median is the "middle" value mode is the most "often" value

Example

13, 18, 13, 14, 13, 16, 14, 21, 13

mean is (13 + 18 + 13 + 14 + 13 + 16 + 14 + 21 + 13) Ă· 9 = 15

median is 13, 13, 13, 13, <14>, 14, 16, 18, 21 = 14

mode is 13

Excercise

1) write a program consists of two functions:

get input n values, findmax.

2) write a program to get input and use findmax to sort the set.

3) write a program to sort input set and then reverse it then print it out.

To do excercises in grader (CH08_XX) you must be familiar with 2D array (matrix). Here is how to create a 2D array (list of list)

create a table of size m, n

you need to "initialize" values in the table

table = [ [ 0 for i in range(m) ] for j in range(n) ]

Here is the code to go over each element in the table

for i in range(m):

for j in range(n):

table[i][j] = ...

Excercise

4) create a matrix 5 x 5 with the value and print it out.

1 2 3 4 5 6 7 8 9 10 ...

5) use the matrix in 4) and double each element. print it out.

6) use the matrix in 4) and transpose it. print it out.

for 5) and 6) make 4) as a function.

Summary

Making a snippet of code into a function is important. it helps "abstract" your code.

A function has "local" parameters.

Name your function to give its meaning (usually a kind of verb).

By now you must be comfortable with all types of data: list, tuple etc.

Have Fun!

Prabhas Chongstitvatana 21 March 2016

Referensi

Dokumen terkait

If the teacher has a good media so the students will be better in learning process especially to write descriptive text.. Based on this situation, the researcher has

The mean in this study refers to the arithmetic mean, one of the measures of central tendency in statistics together with the mode, median, and midrange. Almost all countries

The reason why the writer chooses this title because there are many students who still get difficulty in learning adjective clauses, especially made the errors when write

The next step, the writer calculated the scores of mean, median, mode, standard error of mean, and standard deviation using SPSS 21 program as follows.. 0 5 10 15

The descriptive statistic analyzes data covers the calculation of mean score, mode, median, standard deviation and variance Table 3 The Distribution Analysis of Data Measured in

In this research, the technique of data analysis divided into two general type methodologies, namely; descriptive analysis included mean, median, mode, and standard deviation

The document outlines the objectives, materials, and procedures for a lesson plan on measures of central tendency (mean, median, and mode) in mathematics for 7th-grade

This document is a daily lesson plan for a math class that covers the topic of measures of central tendency, including mean, median, and