{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

10 slide presentation

# 10 slide presentation - Engineering Compuwation Tutorial 10...

This preview shows pages 1–14. Sign up to view the full content.

Engineering Compuwation: Tutorial 10 Problem Solving with Computing, using the Python Language

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
What’s in your toolbox? Print statement, string literals Basic calculator, integer division Variables Built-in functions Math library functions Straight-line programs Branching programs Python lists For loops Nested for loops Strings While loops Converting between number system using Python Matplotlib Program Design File Processing Graphics Functions Scope of Variables Comments Complex Conditions Testing and Debugging Exception Handling Common Loop Patterns Boolean Operators Unit Testing Classes and Objects 2
Today’s Topics: 1 Data Collections 2 Searching 3 Sorting 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Designing with Lists and Classes Our algorithm from Tutorial 09 found ”the highest GPA”. Actually, it found the first student in the file with the highest GPA. What if we need to know all students that tied for the highest GPA? What if we wanted to know the stats of how many students received each GPA score (perhaps we would want to make a graph of the first year engineering GPA distribution at McMaster). 4
Designing with Lists and Classes The program from last tutorial only remembers the current student object, and only the highest GPA (one). for line in infile: name, stnumber, credit, points = string.split(line,"\t") student = Student(name, stnumber, credit, points) #if this student is best so far, remember it. if student.gpa() > best.gpa(): best = student 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Designing with Lists and Classes Lists and classes taken together give us powerful tools for structuring the data in our programs. Let’s put these tools to work in a concrete example by improving our GPA program. 6
Designing with Lists and Classes Algorithm to get list of top GPA students 1 Create a list of all students in the file. 2 Find the highest GPA score in the list . 3 Create a list of students that have this GPA. 7

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Designing with Lists and Classes Algorithm to get list of top GPA students 1 Create a list of all students in the file. 2 Find the highest GPA score in the list . 3 Create a list of students that have this GPA. We can define the following functions def c r e a t e S t u d e n t L i s t ( ) : def highGPA ( s t L i s t ) : def hiGPAstudentList (hiGPA , s t L i s t ) : 7
Designing with Lists and Classes createStudentList from Student import * #why? import string #why? 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Designing with Lists and Classes createStudentList from Student import * #why? import string #why? def createStudentList(): #get filename from user 8
Designing with Lists and Classes createStudentList from Student import * #why? import string #why? def createStudentList(): #get filename from user filename = raw_input("Enter the name of the grade file: ") 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Designing with Lists and Classes createStudentList from Student import * #why? import string #why? def createStudentList(): #get filename from user filename = raw_input("Enter the name of the grade file: ") #open the file for reading 8
Designing with Lists and Classes createStudentList from Student import * #why?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 81

10 slide presentation - Engineering Compuwation Tutorial 10...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online