10 slide presentation - Engineering Compuwation: Tutorial...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering Compuwation: Tutorial 10 Problem Solving with Computing, using the Python Language Whats 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 Todays Topics: 1 Data Collections 2 Searching 3 Sorting 3 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 Designing with Lists and Classes Lists and classes taken together give us powerful tools for structuring the data in our programs. Lets 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 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 createStudentList ( ) : 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 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 Designing with Lists and Classes createStudentList from Student import * #why?...
View Full Document

This note was uploaded on 10/14/2011 for the course ENGINEER CHEM ENG 3 taught by Professor Ghosh during the Spring '11 term at McMaster University.

Page1 / 81

10 slide presentation - Engineering Compuwation: Tutorial...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online