Lecture 2: Variables & Assignments


 Dulcie Mosley
 8 months ago
 Views:
Transcription
1 Lecture 2: Variables & Assignments (Sections ,2.5) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]
2 CS 1110, Lecture 2 Announcements Sections  Start this week! Yay!  Please go only to the Section you are enrolled in  Need to Change your Section or your Lecture? See our Section Swapping Station on Piazza: Enrollment  Lots of turnover in the first week. Don t give up!  Perhaps another class meets your needs? 2
3 Things to do this week Lab 1: Read textbook Chapter , 2.5 Chapter Go to your registered section Complete lab handout You have one week to show your work: to TA by end of lab, or: in consulting hours up to 1 day before your lab, or: in TA (not professor) office hours (but student questions take precedence over this) to TA within first 10 minutes of next week s lab 3
4 Helping you succeed in this class Consultants. ACCEL Lab Green Room Daily office hours (see website) with consultants Very useful when working on assignments ENGRG 1010: AEW Workshops. Additional discussion course open to ALL students Runs parallel to this class optional See website Piazza. Online forum to ask/answer questions Go here first before ing questions Office Hours. Talk to the professors! Olin 128 between lectures 4
5 iclickers Fun! Interactive! Not for a grade; no need to register. 5
6 iclicker Warm Up: Using Python How do you Plan to use Python? A. I want to work mainly in the computer labs 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 6
7 From last time: Types Type: set of values & operations on them Type float: Values: real numbers Ops: +, , *, /, ** Type int: Values: integers Ops: +, , *, //, %, ** Type bool: Values: integers Ops: not, and, or Type str: Values: string literals Double quotes: abc Single quotes: abc Ops: + (concatenation) 7
8 Converting from one type to another Command: <type>(<value>) >>> float(2) 2.0 converts value 2 to type float converts value 2.6 to type int >>> int(2.6) 2 This kind of conversion is also called casting Different from type(<value>) type(<value>) tells you the type <type>(<value>) converts the type 8
9 Implicit (Automatic) Conversions Python sometimes converts types automatically Example: 1/2.0  evaluates to a float: internally: Step 1: Python casts 1 (an int) to 1.0 (a float) Step 2: Python evaluates 1.0/2.0 Behavior depends on whether the conversion is narrowing or widening 9
10 Variable width Types differ in how much information held Convert without losing information? floatàint (e.g., 4.7 to 4) intàfloat (e.g., 4 to 4.0) info lost seems ok Wide = more information capacity From narrow to wide: bool int float 10
11 Widening Conversion From a narrower type to a wider type Python does automatically if needed: Example: 1/2.0 evaluates to a float: 0.5 Example: True + 1 evaluates to an int: 2 True converts to 1 False converts to 0 Note: does not work for str Example: 2 + ab produces an error 11
12 Narrowing Conversion From a wider type to a narrower type Example: int(2.6) causes information to be lost Python never does this automatically Note: you can just always cast Instead of 1/2.0, can write float(1)/2.0 12
13 Types matter! You Decide: What is the right type for my data? When is the right time for conversion (if any) Zip Code as an int? Grades as an int? Lab Grades as a bool? What are your goals: Accuracy? Clarity? Fairness? 13
14 Operator Precedence What is the difference between: 2*(1+3) 2*1 + 3 add, then multiply multiply, then add Operations performed in a set order Parentheses make the order explicit What if there are no parentheses? à Operator Precedence: fixed order to processes operators when no parentheses 14
15 Precedence of Python Operators Exponentiation: ** Unary operators: + Binary arithmetic: * / % Binary arithmetic: + Comparisons: < > <= >= Equality relations: ==!= Precedence goes downwards Parentheses highest Logical ops lowest Same line = same precedence Read ties left to right (except for **) Example: 1/2*3 is (1/2)*3 Logical not Logical and Logical or Section 2.5 in your text See website for more info Major portion of Lab 1 15
16 Operators and Type Conversions Evaluate this expression: Operator Precedence Exponentiation: ** Unary operators: + Binary arithmetic: * / % Binary arithmetic: + Comparisons: < > <= >= Equality relations: ==!= Logical not Logical and Logical or 1/31/17 Variables & Assignments False / 3 A. 3 B. 3.0 C D. 2 E
17 Operators and Type Conversions Evaluate this expression: Operator Precedence Exponentiation: ** Unary operators: + Binary arithmetic: * / % Binary arithmetic: + Comparisons: < > <= >= Equality relations: ==!= Logical not Logical and Logical or 1/31/17 Variables & Assignments False / 3 False
18 New Tool: Variable Assignment An assignment statement: takes an expression evaluates it, and stores the value in a variable Example: variable >>> x = 5 equals sign (just one!) (read right to left) expression evaluates to 5 18
19 Executing Assignment Statements >>> x = 5 >>> Press ENTER and Hmm, looks like nothing happened But something did happen! Python assigned the value 5 to the variable x Internally (and invisible to you): memory location x 5 stored value 19
20 Retrieving Variables >>> x = 5 >>> x 5 >>> Press ENTER and Python tells me the stored value 20
21 In More Detail: Variables (Section 2.1) A variable is a named memory location (box) contains a value (in the box) Examples: Variable names must start with a letter (or _). x area Variable x, with value 5 (of type int) Variable area, w/ value 20.1 (of type float) The type belongs to the value, not to the variable. 1e2 is a float, but e2 is a variable name 21
22 In More Detail: Statements >>> x = 5 >>> Press ENTER and Hm, looks like nothing happened 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) 22
23 Expressions vs. Statements Expression Represents something Python evaluates it End result is a value Examples: 2.3 (3+5)/4 x == 5 Value Complex Expression Statement Does something Python executes it Need not result in a value Examples: x = x = 5 Look so similar but they are not! 23
24 You can assign more than literals >>> x = 5 >>> x = 3.0 ** >>> x = 2 + x x gets 5 x gets the value of this expression x gets 2 plus the current value of x 24
25 Keeping Track of Variables Draw boxes on paper: >>> x = 5 New variable declared? >>> y = 3 Write a new box. x 5 y 3 7 Variable updated? >>> x = 7 Cross out old value. Insert new value. 25
26 Execute the Statement: x = x + 2 Draw variable x on piece of paper: x 5 1. Evaluate the expression x + 2 For x, use the value in variable x Write the expression somewhere on your paper 2. Store the value of the expression in x Cross off the old value in the box Write the new value in the box for x Did you do the same thing as your neighbor? If not, discuss. 26
27 Which one is closest to your answer? A. x 5 7 B. x 5 x 7 C. x 5 x 7 D. \_( )_/ x = x
28 And The Correct Answer Is A. x 5 7 B. x 5 x 7 C. x 5 x 7 D. \_( )_/ x = x
29 Execute the Statement: x = 3.0*x+1.0 Begin with this: x Evaluate the expression 3.0*x Store its value in x Did you do the same thing as your neighbor? If not, discuss. 29
30 Which one is closest to your answer? A. B. x 5 7 x x 22.0 C. x 5 7 x 22.0 D. \_( )_/ x = 3.0*x
31 And The Correct Answer Is A. B. x 5 7 x x 22.0 C. x 5 7 x 22.0 D. \_( )_/ x = 3.0*x
32 Executing an Assignment Statement The command: x = 3.0*x+1.0 Executing the command : 1. Evaluate right hand side 3.0*x Store the value in the variable x s box Requires both evaluate AND store steps Critical mental model for learning Python 32
33 Exercise 1: Understanding Assignment Begin with: Declare a new variable: >>> rate = 4 x rate 4 Execute this assignment: >>> rate = x / rate Did you do the same thing as your neighbor? If not, discuss. 33
34 Which one is closest to your answer? A. x rate B. x rate 4 rate 5.5 C. D. x x rate rate 4 5 E. \_( )_/ rate = x / rate 34
35 And The Correct Answer Is A. x rate B. x rate 4 rate 5.5 C. x D. x rate rate 4 5 rate = x / rate 35
36 Dynamic Typing Python is a dynamically typed language Variables can hold values of any type Variables can hold different types at different times The following is acceptable in Python: >>> x = 1 >>> x = x / 2.0 ç x contains an int value ç x now contains a float value Alternative: a statically typed language Examples: Java, C Each variable restricted to values of just one type 36
37 More Detail: Testing Types Command: type(<value>) Can test a variable: >>> x = 5 >>> type(x) <class 'int > Can test a type with a Boolean expression: >>> type(2) == int True 37
38 Exercise 2: Understanding Assignment Begin with: x rate Execute this assignment: >>> rat = x + rate Did you do the same thing as your neighbor? If not, discuss. 38
39 Which one is closest to your answer? A. x rate B. x rate rat 27.5 C. x D. x rate rate rat 27.5 E. \_( )_/ rat = x + rate 39
40 And The Correct Answer Is A. x rate B. x rate rat 27.5 C. x D. x rate rate rat 27.5 Spelling Matters! rat = x + rate 40
Lecture 1. Course Overview, Python Basics
Lecture 1 Course Overview, Python Basics We Are Very Full! Lectures and Labs are at firecode capacity We cannot add sections or seats to lectures You may have to wait until someone drops No auditors are
More informationCourse Overview, Python Basics
CS 1110: Introduction to Computing Using Python Lecture 1 Course Overview, Python Basics [Andersen, Gries, Lee, Marschner, Van Loan, White] Interlude: Why learn to program? (which is subtly distinct from,
More informationcs1114 REVIEW of details test closed laptop period
python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any
More informationLecture 4: Defining Functions
http://www.cs.cornell.edu/courses/cs0/208sp Lecture 4: Defining Functions (Ch. 3.43.) CS 0 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W.
More informationProgram Fundamentals
Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java
More informationIteration and For Loops
CS 1110: Introduction to Computing Using Python Lecture 11 Iteration and For Loops [Andersen, Gries, Lee, Marschner, Van Loan, White] Rooms: Announcements: Prelim 1 aa200 jjm200 Baker Laboratory 200 jjm201
More informationOperators. Lecture 3 COP 3014 Spring January 16, 2018
Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special builtin symbols that have functionality, and work on operands operand an input to an operator Arity  how many operands an operator
More informationESc101 : Fundamental of Computing
ESc101 : Fundamental of Computing I Semester 200809 Lecture 9+10 Types Range of numeric types and literals (constants) in JAVA Expressions with values of mixed types 1 I : Range of numeric types and literals
More informationCS1110. Lecture 6: Function calls
CS1110 Lecture 6: Function calls Announcements Grades for Lab 1 should all be posted in CMS. Please verify that you have a 1 if you checked off the lab. Let course staff know if your grade is missing!
More informationTopic 4 Expressions and variables
Topic 4 Expressions and variables "Once a person has understood the way variables are used in programming, he has understood the quintessence of programming." Professor Edsger W. Dijkstra Based on slides
More informationChapter 3 Structure of a C Program
Chapter 3 Structure of a C Program Objectives To be able to list and describe the six expression categories To understand the rules of precedence and associativity in evaluating expressions To understand
More informationType Conversion. and. Statements
and Statements Type conversion changing a value from one type to another Void Integral Floating Point Derived Boolean Character Integer Real Imaginary Complex no fractional part fractional part 2 tj Suppose
More informationObjects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003
Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationLecture 3. Functions & Modules
Lecture 3 Functions & Modules Labs this Week Lab 1 is due at the beginning of your lab If it is not yet by then, you cannot get credit Only exception is for students who added late (Those students should
More informationJava Primer 1: Types, Classes and Operators
Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,
More informationLecture 6: Specifications & Testing
http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 6: Specifications & Testing (Sections 4.9, 9.5) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Shortcircuiting main method public static
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 21: Expressions and Variables reading: 2.12.2 Copyright 2009 by Pearson Education Data and expressions reading: 2.1 selfcheck: 14 videos: Ch. 2 #1 Copyright
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Shortcircuiting main method public static
More informationValues and Variables 1 / 30
Values and Variables 1 / 30 Values 2 / 30 Computing Computing is any purposeful activity that marries the representation of some dynamic domain with the representation of some dynamic machine that provides
More informationMore Programming Constructs  Introduction
More Programming Constructs  Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and
More informationCS 1110, LAB 3: STRINGS; TESTING
CS 1110, LAB 3: STRINGS; TESTING http://www.cs.cornell.edu/courses/cs1110/2017sp/labs/lab03.pdf First Name: Last Name: NetID: Getting Credit: Deadline: the first 10 minutes of (your) lab two weeks from
More informationNumerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2
Numerical Computing in C and C++ Jamie Griffin Semester A 2017 Lecture 2 Visual Studio in QM PC rooms Microsoft Visual Studio Community 2015. Bancroft Building 1.15a; Queen s W207, EB7; Engineering W128.D.
More informationLecture 18: Using Classes Effectively (Chapter 16)
http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 18: Using Classes Effectively (Chapter 16) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,
More informationArithmetic Expressions in C
Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
More informationWELCOME! (download slides and.py files and follow along!) LECTURE 1
WELCOME! (download slides and.py files and follow along!) 6.0001 LECTURE 1 6.0001 LECTURE 1 1 TODAY course info what is computation python basics mathematical operations python variables and types NOTE:
More informationSelection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington
Selection s CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1 Book reference Book: The practice of Computing Using Python 2nd edition Second hand book
More informationCS1110. Lecture 6: Function calls
CS1110 Lecture 6: Function calls Announcements Additional space in labs: We have added some space and staffing to the 12:20 and 1:25 labs on Tuesday. There is still space to move into these labs. Printed
More informationLecture 4. Defining Functions
Lecture 4 Defining Functions Academic Integrity Quiz Remember: quiz about the course AI policy Have posted grades for completed quizes Right now, missing ~90 enrolled students If did not receive perfect,
More information! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char
Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated
More informationVariables. Store information needed by the program
Variables Store information needed by the program Must have a TYPE int  can only store a number without a fractional part float, double  can store any number, with or without a fractional part (double
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data
More informationLecture 8: Conditionals & Control Flow (Sections ) CS 1110 Introduction to Computing Using Python
http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 8: Conditionals & Control Flow (Sections 5.15.7) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,
More informationInf2C  Computer Systems Lecture 2 Data Representation
Inf2C  Computer Systems Lecture 2 Data Representation Boris Grot School of Informatics University of Edinburgh Last lecture Moore s law Types of computer systems Computer components Computer system stack
More informationCSE 20. Lecture 4: Number System and Boolean Function. CSE 20: Lecture2
CSE 20 Lecture 4: Number System and Boolean Function Next Weeks Next week we will do Unit:NT, Section 1. There will be an assignment set posted today. It is just for practice. Boolean Functions and Number
More informationMidterms Save the Dates!
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Arithmetic Operators Type Conversion Constants Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.12.5, Ch
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 05 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions / Comments? recap and some more details about variables, and if / else statements do lab work
More informationMODULE 02: BASIC COMPUTATION IN JAVA
MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment
More informationOperators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur
Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators
More informationContents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual
Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types
More informationAnd Parallelism. Parallelism in Prolog. OR Parallelism
Parallelism in Prolog And Parallelism One reason that Prolog is of interest to computer scientists is that its search mechanism lends itself to parallel evaluation. In fact, it supports two different kinds
More informationData Types. Data Types. Integer Types. Signed Integers
Data Types Data Types Dr. TGI Fernando 1 2 The fundamental building blocks of any programming language. What is a data type? A data type is a set of values and a set of operations define on these values.
More informationWhat did we talk about last time? Examples switch statements
Week 4  Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation
More information1.00 Lecture 4. Promotion
1.00 Lecture 4 Data Types, Operators Reading for next time: Big Java: sections 6.16.4 Promotion increasing capacity Data Type Allowed Promotions double None float double long float,double int long,float,double
More informationChapter 7. Expressions and Assignment Statements (updated edition 11) ISBN
Chapter 7 Expressions and Assignment Statements (updated edition 11) ISBN 0321493621 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean
More informationVariable and Data Type I
The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved
More information2: Basics of Java Programming
2: Basics of Java Programming CSC 1051 Algorithms and Data Structures I Dr. MaryAngela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/
More informationSoftware II: Principles of Programming Languages. Why Expressions?
Software II: Principles of Programming Languages Lecture 7 Expressions and Assignment Statements Why Expressions? Expressions are the fundamental means of specifying computations in a programming language
More informationLSystem Fractal Generator: Language Reference Manual
LSystem Fractal Generator: Language Reference Manual Michael Eng, Jervis Muindi, Timothy Sun Contents 1 Program Definition 3 2 Lexical Conventions 3 2.1 Comments...............................................
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationPython Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016
Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016 Today s lecture u What is Python? u Displaying text on screen using print() u Variables u Numbers and basic arithmetic u Getting input
More informationVariable and Data Type I
Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store
More informationMARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012
MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)
More informationLab 1: Setup 12:00 PM, Sep 10, 2017
CS17 Integrated Introduction to Computer Science Hughes Lab 1: Setup 12:00 PM, Sep 10, 2017 Contents 1 Your friendly lab TAs 1 2 Pair programming 1 3 Welcome to lab 2 4 The file system 2 5 Intro to terminal
More informationFundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials
Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals
More informationCS 430 Spring Mike Lam, Professor. Data Types and Type Checking
CS 430 Spring 2015 Mike Lam, Professor Data Types and Type Checking Type Systems Type system Rules about valid types, type compatibility, and how data values can be used Benefits of a robust type system
More informationLecture 6. Assignments. Summary  Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4
Assignments Lecture 6 Complete for Project 1 Reading: 3.1, 3.2, 3.3, 3.4 Summary Program Parts Summary  Variables Class Header (class name matches the file name prefix) Class Body Because this is a program,
More informationProfessor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators
1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with
More informationfalse, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4
1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new ZhengLiang Lu Java Programming 44
More informationCSE 142, Summer 2014
CSE 142, Summer 2014 Lecture 2: Static Methods Expressions reading: 1.4 2.1 Algorithms algorithm: A list of steps for solving a problem. Example algorithm: "Bake sugar cookies" Mix the dry ingredients.
More informationChapter 2 Elementary Programming
Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical
More informationLesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL
Lesson 02 Data Types and Statements MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Constants Data Types
More informationPython Games. Session 1 By Declan Fox
Python Games Session 1 By Declan Fox Rules General Information WiFi Name: CoderDojo Password: coderdojowireless Website: http://cdathenry.wordpress.com/ Plans for this year Command line interface at first
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3  Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationCpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection
CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection Overview By the end of the lab, you will be able to: declare variables perform basic arithmetic operations on integer variables
More informationPointers (continued), arrays and strings
Pointers (continued), arrays and strings 1 Last week We have seen pointers, e.g. of type char *p with the operators * and & These are tricky to understand, unless you draw pictures 2 Pointer arithmetic
More informationFormal Languages and Compilers Lecture X Intermediate Code Generation
Formal Languages and Compilers Lecture X Intermediate Code Generation Free University of BozenBolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/
More informationLecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4
Assignments Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4 Lecture 6 Complete for Lab 4, Project 1 Note: Slides 12 19 are summary slides for Chapter 2. They overview much of what we covered but are not complete.
More informationSixth lecture; classes, objects, reference operator.
Sixth lecture; classes, objects, reference operator. 1 Some notes on the administration of the class: From here on out, homework assignments should be a bit shorter, and labs a bit longer. My office hours
More informationLecture 2 Tao Wang 1
Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationCSE 142, Summer 2015
CSE 142, Summer 2015 Lecture 2: Static Methods Expressions reading: 1.4 2.1 The Mechanical Turk 2 Escape Characters System.out.println( ab\ \\\\\\/\td ); Output: ab \\\/ d 3 Algorithms algorithm: A list
More informationVB FUNCTIONS AND OPERATORS
VB FUNCTIONS AND OPERATORS In der to compute inputs from users and generate results, we need to use various mathematical operats. In Visual Basic, other than the addition (+) and subtraction (), the symbols
More informationCS 11 java track: lecture 1
CS 11 java track: lecture 1 Administrivia need a CS cluster account http://www.cs.caltech.edu/ cgibin/sysadmin/account_request.cgi need to know UNIX www.its.caltech.edu/its/facilities/labsclusters/ unix/unixtutorial.shtml
More informationSTUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, ifelse Statements, Pseudocode
STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a highlevel
More informationCS/ENGRD 2110 ObjectOriented Programming and Data Structures Spring 2012 Thorsten Joachims
CS/ENGRD 2110 ObjectOriented Programming and Data Structures Spring 2012 Thorsten Joachims Lecture 1: Overview http://courses.cs.cornell.edu/cs2110 1 Course Staff Instructor Thorsten Joachims (tj@cs.cornell.edu)
More informationLecture 7. Memory in Python
Lecture 7 Memory in Python Announcements For This Lecture Readings Reread Chapter 3 No reading for Thursday Lab Work on Assignment Credit when submit A Nothing else to do Assignment Moved to Fri, Sep.
More informationCS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay
CS 101 Computer Programming and utilization Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building Bombay Lecture 4, Conditional execution of instructions Friday, August
More informationFundamentals of Structured Programming
Fundamentals of Structured Programming Dr. Salma Hamdy s.hamdy@cis.asu.edu.eg 1 Course Logistics Staff Teachers Prof. Mohamed Roushdy (Dean) Dr. Salma Hamdy Contact: s.hamdy@cis.asu.edu.eg Office: FCIS,
More informationMITOCW watch?v=rvrktjxvko
MITOCW watch?v=rvrktjxvko The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To
More informationChapter 3 Syntax, Errors, and Debugging. Fundamentals of Java
Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different
More informationIntroduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193winter15
1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details
More informationVariables and Constants
HOUR 3 Variables and Constants Programs need a way to store the data they use. Variables and constants offer various ways to work with numbers and other values. In this hour you learn: How to declare and
More informationChapter 7. Expressions and Assignment Statements
Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions ShortCircuit Evaluation Assignment
More informationPython for Nonprogrammers
Python for Nonprogrammers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
More informationCOMP202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015
COMP202: Foundations of Programming Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 Announcements Midterm Exams on 4 th of June (12:35 14:35) Room allocation will be announced soon
More information1/16/12. CS 112 Introduction to Programming. A Foundation for Programming. (Spring 2012) Lecture #4: Builtin Types of Data. The Computer s View
1/16/12 A Foundation for Programming CS 112 Introduction to Programming (Spring 2012) any program you might want to write Lecture #4: Builtin Types of Data objects Zhong Shao methods and classes graphics,
More informationPython Input, output and variables
Today s lecture Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016! What is Python?! Displaying text on screen using print()! Variables! Numbers and basic arithmetic! Getting input from
More informationData Types and Basic Calculation
Data Types and Basic Calculation Intrinsic Data Types Fortran supports five intrinsic data types: 1. INTEGER for exact whole numbers e.g., 1, 100, 534, 18, 654321, etc. 2. REAL for approximate, fractional
More informationPython for C programmers
Python for C programmers The basics of Python are fairly simple to learn, if you already know how another structured language (like C) works. So we will walk through these basics here. This is only intended
More informationPython Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018
Python Input, output and variables Lecture 23 COMPSCI111/111G SS 2018 1 Today s lecture What is Python? Displaying text on screen using print() Variables Numbers and basic arithmetic Getting input from
More informationBuilding Java Programs Chapter 2
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. bug 2 An Insect 3 Software Flaw 4 Bug, Kentucky 5 Bug Eyed 6 Cheesy Movie 7 Punch Buggy
More informationBuilding Java Programs Chapter 2. bug. Primitive Data and Definite Loops. Copyright (c) Pearson All rights reserved. Software Flaw.
Building Java Programs Chapter 2 bug Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. 2 An Insect Software Flaw 3 4 Bug, Kentucky Bug Eyed 5 Cheesy Movie 6 Punch Buggy
More informationCpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection
CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection Overview By the end of the lab, you will be able to: declare variables perform basic arithmetic operations on integer variables
More informationFile Handling in C. EECS 2031 Fall October 27, 2014
File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically
More informationCourse Outline Introduction to CProgramming
ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to CProgramming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,
More informationPython 2 Conditionals and loops Matthew Egbert CS111
Python 2 Conditionals and loops Matthew Egbert CS111 Yesterday's Lecture Input and Output user_input_as_str = input('prompt: ') print('hello. You entered: '+ user_input_as_str) Comments # everything to
More information