review-10 - CMSC 143 M idter m Review Keith OHara...

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

View Full Document Right Arrow Icon
Oct 6 2010 CMSC143 - O'Hara 1 1 CMSC 143 Midterm Review Keith O’Hara [email protected]
Image of page 1

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

View Full Document Right Arrow Icon
Oct 6 2010 CMSC143 - O'Hara 2 Administrative Midterm – Friday, October 8 Assignment 3 – October 15th
Image of page 2
Oct 6 2010 CMSC143 - O'Hara 3 Midterm You and a pencil Closed Books Closed Notes Closed Laptops Closed Neighbors Closed Robot! 80 minutes Python Terminology Reading Programs Writing Programs Robots homework material is fair game
Image of page 3

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

View Full Document Right Arrow Icon
Topics Expressions Variables Functions For & While loops Conditionals Recursion Lists Objects Oct 6 2010 CMSC143 - O'Hara 4
Image of page 4
Oct 6 2010 CMSC143 - O'Hara 5 Operators Python has many operators. Some examples are: +, -, *, /, %, >, <, == print Operators perform an action on one or more operands. Some operators accept operands before and after themselves: operand1 + operand2 , or 3 + 5 Others are followed by one or more operands until the end of the line, such as: print “Hi!”, 32, 48 When operators are evaluated, they perform action on their operands, and produce a new value.
Image of page 5

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

View Full Document Right Arrow Icon
Oct 6 2010 CMSC143 - O'Hara 6 Expressions Code snippets that evaluate to some value . 3+2 3*2 3**2 (3+2)*(4+2) 3.0/2.0 “hello” + “world”
Image of page 6
Oct 6 2010 CMSC143 - O'Hara 7 What’s the Type? -1 -1.5 30000 “30000” 30000.0 3.14 [-1, -1.5, “30000”]
Image of page 7

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

View Full Document Right Arrow Icon
Oct 6 2010 CMSC143 - O'Hara 8 Types of Values Integers (like integers in math) -1, -2, 300000, 0 Float ing Points (like “decimals”) -1.5, 1.5, 3.1415, 1.0 Character (like symbol of an alphabet) ‘a’, ‘b’, ‘c’, ‘z’ Strings (a string of characters) “CMSC”, “143”, “rocks”, “” Lists (a collection of values) [“CMSC”, “143”, “rocks”]; [-1, -2, 3000]; [] type(“rocks”), type(10)
Image of page 8
Oct 6 2010 CMSC143 - O'Hara 9 Integer Arithmetic Addition (+) Subtraction (-) Multiplication (*) Integer Division (/) 4/2 5/2 Modulo/Remainder(%) 4%2 5%2 Exponentiation (**) 2**3 2**4 Integer Division (/) 4/2 # evals to 2 5/2 # evals to 2 Modulo/Remainder(%) 4%2 # evals to 0 5%2 # evals to 1 Exponentiation (**) 2**3 # evals to 8 2**4 # evals to 16
Image of page 9

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

View Full Document Right Arrow Icon
Oct 6 2010 CMSC143 - O'Hara 10 Float Arithmetic Addition (+) Subtraction (-) Multiplication (*) Integer Division (/) 4.0/2.0 5.0/2.0 Modulo/Remainder(%) 4.0%2.0 5.0%2.0 Exponentiation (**) 2.0**3.0 2.0**4.0 Integer Division (/) 4.0/2.0 # evals to 2.0 5.0/2.0 # evals to 2.5 Modulo/Remainder(%) 4.0%2.0 # evals to 0.0 5.0%2.0 # evals to 1.0 Exponentiation (**) 2.0**3.0 # evals to 8.0 2.0**4.0 # evals to 16.0
Image of page 10
Oct 6 2010 CMSC143 - O'Hara 11 Sequence “Arithmetic” Addition (+) - Combines (concatenates) the sequence “CMSC” + “143” # evals to “CMSC143” Multiplication (*) - Repeats the sequence “CS” *3 # evals to “CSCSCS”
Image of page 11

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

View Full Document Right Arrow Icon
Oct 6 2010 CMSC143 - O'Hara 12 Have some Type-Sense! Your expressions should make sense in terms of what type they are Some make perfect sense 3 + 4 = 7 [int + int = int] Some expressions make no sense “hello” + 4 [ string + int] Some expressions make (uncommon) sense 4.0 + 3 [float + int] 4.0 + 3 = 7.0 [float + int = float] “CS” * 3 = “CSCSCS” [string * int = string]
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern