MCS 177 Lab Fall 2014 Sept. 2, 2014
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Contact Info Course Instructor: Louis Yu Lab Instructors: Mike Hvidsten Jeff Engelhardt Lab Assistants 11:30: Andrew Haisting 2:30: Dustin Luhmann MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Today’s schedule Course/Lab Details Python and Idle Python Intro (Sec in textbook) Tasks 1 and 2 of Project 1 (if time) MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Course/Lab Course Website: Lectures – Monday, Wednesday, Friday Read Assigned sections before class (see class schedule) Lab Work – Tuesday, Thursday Projects are linked from course site This week – Intro (nothing to hand in) Submit code via Moodle Lab notes/slides at MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Python – Course Programming Language Python is an open source scripting language. Developed by Guido van Rossum in the early 1990s Named after Monty Python Available on MCS computers Available for download from MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Why Python? MCS 177, 9/2/14 Simple Syntax – we can focus on solving problems, learning concepts, not coding syntax Object-Oriented – all values are essentially objects Widely used (Google spider and search engine) Powerful String and Math libraries Dynamic Typing: Variables do not need to have pre- defined types
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Idle GUI Environment: MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Let’s Get Started! Log on to your computer (user name = name) Start Idle Try some basic arithmetic examples MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Arithmetic Operations MCS 177, 9/2/14 OperatorOperation +Addition -Subtraction *Multiplication /Float division //Integer division %Remainder **Exponentiation abs()Absolute value
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Numerical Data Types Integer (int) vs Floating Point (float) How can we tell which is which? A numeric value without a decimal point produces an int value A numerical value that has a decimal point is represented by a float (even if the fractional part is 0) MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Numerical Operations >>> >>> >>> 3.0* >>> 3*4 12 >>> 10.0/ >>> 10/ >>> 10 // 3 3 >>> 10.0 // MCS 177, 9/2/14 Operations on ints produce ints (except for /) Operations on floats produce floats, Mixed operations are converted to floats
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Variable Assignment (Section 1.5) MCS 177, 9/2/14 As in mathematics, much of the power of computer programs is in the use of variables Python variables are identified by name Must start with a letter Ex: x=2, a_1 = x+3
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Example MCS 177, 9/2/14 We want to calculate the volume of a cylinder volume = area of base * height Variables?
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Example MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Diagram for Simple Assignment in Python MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Changing Radius value has no effect on cylinderVolume! Why not? MCS 177, 9/2/
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu How do we make change? MCS 177, 9/2/14 Need to re-evaluate baseArea and cylinderVolume
GUSTAVUS ADOLPHUS COLLEGEgustavus.edu If time, Start working on Tasks 1 and 2 of Project 1 MCS 177, 9/2/14