variables assignment announcements for today
play

Variables & Assignment Announcements for Today If Not Done - PowerPoint PPT Presentation

Lecture 2 Variables & Assignment Announcements for Today If Not Done Already Lab 1 Please stay in your section Enroll in Piazza If you drop, you are stuck Sign into CMS E-mail conflicts to Jenna jls478@cornell.edu


  1. Lecture 2 Variables & Assignment

  2. Announcements for Today If Not Done Already Lab 1 • Please stay in your section • Enroll in Piazza § If you drop, you are stuck • Sign into CMS § E-mail conflicts to Jenna § jls478@cornell.edu § Fill out the Survey § Will review by next week § Complete AI Quiz • Have one week to complete • ( Optional ) textbook § Complete in online system § Chapter 1 (browse) § Show at start of next lab § Chapter 2 (in detail) • But finish Lab 0 TODAY 8/27/18 Variables & Assignments 2

  3. Helping You Succeed in this Class • Consultants. ACCEL Lab Green Room § Daily office hours (see website) with consultants § Very useful when working on assignments • AEW Workshops . Additional discussion course § Runs parallel to this class – completely optional § See website; talk to advisors in Olin 167. • Piazza. Online forum to ask and answer questions § Go here first before sending question in e-mail • Office Hours. Talk to the professor! § Available outside Call Auditorium between lectures 8/27/18 Variables & Assignments 3

  4. Labs vs. Assignments Labs Assignments • Held every week • Every two weeks § First one due Sep. 18 • Graded on completeness § Always S/U • Graded on correctness § Try again if not finished § Assign points out of 100 • Indirect affect on grade • But first one is for mastery § Resubmit until perfect grade § Can miss up to 2 labs § After that, grade reduced • 40% of your final grade • Similar to language drills • Designed to be more fun § Simple, but take time § Graphics, game design 8/27/18 Variables & Assignments 4

  5. ACCEL Labs • Enter from front • Walk to staircase on left • Go up the stairs 8/27/18 Variables & Assignments 5

  6. Academic Integrity • Every semester we have cases of plagiarism § Claiming the work of others as your own § This is an Academic Integrity violation • The policy this year has changed! § Do not listen to (non-staff) upperclassmen § Look at the course website for the new details • Complete Academic Integrity Quiz on CMS § Must complete successfully to stay in class 8/27/18 Variables & Assignments 6

  7. iClickers • Have you registered your iclicker? • If not, visit § http://atcsupport.cit.cornell.edu/pollsrvc/ • Instructions on iClickers can be found here: § http://pollinghelp.cit.cornell.edu/iclicker-basics/ § Find these links on the course webpage § Click � Texts/iClickers � § Look under “iClickers” 8/27/18 Variables & Assignments 7

  8. Warm-Up: Using Python • How do you plan to use Python? A. I want to work mainly in the ACCEL lab B. I want to use my own Windows computer C. I want to use my own Macintosh computer D. I want to use my own Linux computer E. I will use whatever I can get my hands on 8/27/18 Variables & Assignments 8

  9. Type: Set of values and the operations on them • Type int : • Type str : § Values : integers § Values : string literals • Double quotes: "abc" § Ops : +, –, *, //, %, ** • Single quotes: 'abc' • Type float : § Ops : + (concatenation) § Values : real numbers § Ops : +, –, *, /, ** • Type bool : Will see more types § Values : True and False in a few weeks § Ops : not, and, or 8/27/18 Variables & Assignments 9

  10. Converting Values Between Types • Basic form: type ( value ) § float(2) converts value 2 to type float (value now 2.0) § int(2.6) converts value 2.6 to type int (value now 2) § Explicit conversion is also called “casting” • Narrow to wide: bool ⇒ int ⇒ float • Widening . Python does automatically if needed § Example : 1/2.0 evaluates to 0.5 (casts 1 to float ) • Narrowing . Python never does this automatically § Narrowing conversions cause information to be lost § Example : float(int(2.6)) evaluates to 2.0 8/27/18 Variables & Assignments 10

  11. Operator Precedence • What is the difference between the following? § 2*(1+3) § 2*1 + 3 • Operations are performed in a set order § Parentheses make the order explicit § What happens when there are no parentheses? • Operator Precedence : The fixed order Python processes operators in absence of parentheses 8/27/18 Variables & Assignments 11

  12. Operator Precedence • What is the difference between the following? § 2*(1+3) add, then multiply § 2*1 + 3 multiply, then add • Operations are performed in a set order § Parentheses make the order explicit § What happens when there are no parentheses? • Operator Precedence : The fixed order Python processes operators in absence of parentheses 8/27/18 Variables & Assignments 12

  13. Precedence of Python Operators • Exponentiation : ** • Precedence goes downwards § Parentheses highest • Unary operators : + – § Logical ops lowest • Binary arithmetic : * / % • Same line = same precedence § Read “ties” left to right • Binary arithmetic : + – § Example: 1/2*3 is (1/2)*3 • Comparisons : < > <= >= • Equality relations : == != • Section 2.7 in your text • Logical not • See website for more info • Logical and • Was major portion of Lab 1 • Logical or 8/27/18 Variables & Assignments 13

  14. Expressions vs Statements Expression Statement • Represents something • Does something § Python evaluates it § Python executes it § End result is a value § Need not result in a value • Examples: • Examples: Value § 2.3 § print('Hello') § (3+5)/4 § import sys Complex Expression Will see later this is not a clear cut separation 8/27/18 Variables & Assignments 14

  15. Variables (Section 2.1) • A variable § is a named memory location ( box ) § contains a value (in the box) § can be used in expressions • Examples: Variable names Variable x , with value 5 (of type int ) x 5 must start with a letter (or _). area 20.1 Variable area , w/ value 20.1 (of type float ) 8/27/18 Variables & Assignments 15

  16. Variables (Section 2.1) • A variable § is a named memory location ( box ) § contains a value (in the box) § can be used in expressions The type belongs • Examples: to the value , not to the variable . Variable names Variable x , with value 5 (of type int ) x 5 must start with a letter (or _). area 20.1 Variable area , w/ value 20.1 (of type float ) 8/27/18 Variables & Assignments 16

  17. Variables (Section 2.1) • A variable § is a named memory location ( box ) The value in the box is § contains a value (in the box) then used in evaluating § can be used in expressions the expression. The type belongs • Examples: to the value , not to the variable . Variable names Variable x , with value 5 (of type int ) x 5 must start with a letter (or _). area 20.1 Variable area , w/ value 20.1 (of type float ) 8/27/18 Variables & Assignments 17

  18. Variables (Section 2.1) • A variable § is a named memory location ( box ) The value in the box is § contains a value (in the box) then used in evaluating § can be used in expressions the expression. The type belongs • Examples: to the value , not to the variable . Variable names Variable x , with value 5 (of type int ) x 5 must start with a letter (or _). area 20.1 Variable area , w/ value 20.1 (of type float ) 1e2 is a float , but e2 is a variable name 8/27/18 Variables & Assignments 18

  19. Variables and Assignment Statements • Variables are created by assignment statements § Create a new variable name and give it a value x = 5 • This is a statement , not an expression § Tells the computer to DO something (not give a value) § Typing it into >>> gets no response (but it is working) • Assignment statements can have expressions in them § These expressions can even have variables in them x = x + 2 Two steps to execute an assignment: 1. evaluate the expression on the right 2. store the result in the variable on the left

  20. Variables and Assignment Statements • Variables are created by assignment statements § Create a new variable name and give it a value the value x = 5 the variable • This is a statement , not an expression § Tells the computer to DO something (not give a value) § Typing it into >>> gets no response (but it is working) • Assignment statements can have expressions in them § These expressions can even have variables in them x = x + 2 Two steps to execute an assignment: 1. evaluate the expression on the right 2. store the result in the variable on the left

  21. Variables and Assignment Statements • Variables are created by assignment statements § Create a new variable name and give it a value the value x = 5 x the variable • This is a statement , not an expression § Tells the computer to DO something (not give a value) § Typing it into >>> gets no response (but it is working) • Assignment statements can have expressions in them § These expressions can even have variables in them x = x + 2 Two steps to execute an assignment: 1. evaluate the expression on the right 2. store the result in the variable on the left

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend