Upload
hop-langley
View
33
Download
0
Tags:
Embed Size (px)
DESCRIPTION
MCS 177 Lab Fall 2014. Sept. 2, 2014. MCS 177, 9/2/14. Contact Info. Course Instructor: Louis Yu [email protected] Lab Instructors: Mike Hvidsten [email protected] Jeff Engelhardt [email protected] Lab Assistants 11:30: Andrew Haisting ( [email protected] ) - PowerPoint PPT Presentation
Citation preview
MCS 177 Lab Fall 2014
Sept. 2, 2014
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
Contact Info
• Course Instructor: Louis Yu [email protected]
• Lab Instructors: • Mike Hvidsten [email protected]• Jeff Engelhardt [email protected]
• Lab Assistants11:30: Andrew Haisting ([email protected]) 2:30: Dustin Luhmann ([email protected])
MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
Today’s schedule
•C
ourse/Lab Details
•P
ython and Idle
•P
ython Intro (Sec 1.1-1.5 in textbook)
•T
asks 1 and 2 of Project 1 (if time)
MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
Course/Lab
•C
ourse Website: www.gac.edu/~lyu/teaching/mcs177-f14/
•L
ectures – Monday, Wednesday, Friday
• Read Assigned sections before class (see class schedule)
•L
ab Work – Tuesday, Thursday
• Projects are linked from course site
• This week – Intro (nothing to hand in)
• Submit code via Moodle
•L
ab notes/slides at www.gac.edu/~hvidsten/courses/MC177
MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGE gustavus.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
http://www.python.org
MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGE gustavus.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 COLLEGE gustavus.edu
Idle GUI Environment:
MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
Let’s Get Started!
•L
og on to your computer (user name = email name)
•S
tart Idle
•T
ry some basic arithmetic examples
MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
Arithmetic Operations
MCS 177, 9/2/14
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Float division
// Integer division
% Remainder
** Exponentiation
abs() Absolute value
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
Numerical Data Types
•I
nteger (int) vs Floating Point (float)
•H
ow can we tell which is which?A numeric value without a decimal point produces an int
valueA 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 COLLEGE gustavus.edu
Numerical Operations
>>> 3.0+4.07.0>>> 3+47>>> 3.0*412.0>>> 3*412>>> 10.0/3.03.3333333333333335>>> 10/33.3333333333333335>>> 10 // 33>>> 10.0 // 3.03.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 COLLEGE gustavus.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 COLLEGE gustavus.edu
Example
MCS 177, 9/2/14
•We want to calculate the volume of a cylinder
•volume = area of base * height
•Variables?
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
Example
MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
Diagram for Simple Assignment in Python
MCS 177, 9/2/14
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
Changing Radius value has no effect on cylinderVolume! Why not?
MCS 177, 9/2/14
10.0
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
How do we make change?
MCS 177, 9/2/14
•Need to re-evaluate baseArea and cylinderVolume
GUSTAVUS ADOLPHUS COLLEGE gustavus.edu
If time, Start working on Tasks 1 and 2 of Project 1
MCS 177, 9/2/14