CS 141, Lecture 3. Please login to the Math/Programming profile, and look for IDLE (3.4 or the unnumbered. <-- fine <-- fine <-- broken

Similar documents
1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

Lecture 3. Input, Output and Data Types

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Spring 2017 CS 1110/1111 Exam 1

PYTHON. Values and Variables

CS 115 Lecture 4. More Python; testing software. Neil Moore

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

Reviewing all Topics this term

ENGR 101 Engineering Design Workshop

Arithmetic Expressions in C

Full file at

Introduction to TURING

CS 111X - Fall Test 1

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

Python 2 Conditionals and loops Matthew Egbert CS111

Chapter Two PROGRAMMING WITH NUMBERS AND STRINGS

CS177 Python Programming. Recitation 2 - Computing with Numbers

Lab 1: Input, Processing, and Output This lab accompanies Chapter 2 of Starting Out with Programming Logic & Design.

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Python Input, output and variables

T H E I N T E R A C T I V E S H E L L

Fundamentals: Expressions and Assignment

Fundamentals of Programming Session 8

Chapter 2 Getting Started with Python

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Expressions and Variables

CSC 120 Computer Science for the Sciences. Week 1 Lecture 2. UofT St. George January 11, 2016

2 nd Week Lecture Notes

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

Visual C# Instructor s Manual Table of Contents

ENGR 102 Engineering Lab I - Computation

>>> * *(25**0.16) *10*(25**0.16)

BASIC ELEMENTS OF A COMPUTER PROGRAM

Python Day 3 11/28/16

COMP Primitive and Class Types. Yi Hong May 14, 2015

CSC 221: Introduction to Programming. Fall 2013

Lecture 1. Types, Expressions, & Variables

Level 3 Computing Year 2 Lecturer: Phil Smith

Lecture 3 Tao Wang 1

Week 3 Lecture 2. Types Constants and Variables

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

Control Structures. A program can proceed: Sequentially Selectively (branch) - making a choice Repetitively (iteratively) - looping

NUMBER SENSE AND OPERATIONS. Competency 0001 Understand the structure of numeration systems and multiple representations of numbers.

Computer Programming : C++

CSc 110, Spring 2017 Lecture 3: Expressions, Variables and Loops. Adapted from slides by Marty Stepp and Stuart Reges

Introduction to Programming

Chapter 3 : Informatics Practices. Class XI ( As per CBSE Board) Python Fundamentals. Visit : python.mykvs.in for regular updates

CS 1803 Individual Homework 1 Python Practice Due: Wednesday, January 26th, before 6 PM Out of 100 points

Not-So-Mini-Lecture 6. Modules & Scripts

1. What is the minimum number of bits needed to store a single piece of data representing: a. An integer between 0 and 100?

Lecture 3. Functions & Modules

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

LECTURE 02 INTRODUCTION TO C++

PYTHON- AN INNOVATION

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Week One: Introduction A SHORT INTRODUCTION TO HARDWARE, SOFTWARE, AND ALGORITHM DEVELOPMENT

MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Notes on Chapter 1 Variables and String

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

CS 1428 Programming Assignment 2 Due Wednesday September 19 th :15 am Section 3 3:45 pm Section 4

Chapter 2. Lexical Elements & Operators

Intro to Python & Programming. C-START Python PD Workshop

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

CS Kangmei Yang. Page 1

Getting Started Values, Expressions, and Statements CS GMU

CS 1803 Pair Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 29th, before 6 PM Out of 100 points

Introduction to Programming

Introduction to Python

Chapter 17. Fundamental Concepts Expressed in JavaScript

MODULE 02: BASIC COMPUTATION IN JAVA

These are reserved words of the C language. For example int, float, if, else, for, while etc.

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

COMP 110 Introduction to Programming. What did we discuss?

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

GeoCode Language Reference Manual

Chapter 2: Introduction to C++

1. The programming language C is more than 30 years old. True or False? (Circle your choice.)

Lecture 1. Course Overview, Python Basics

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Python Unit

Programming with Python

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

More about Binary 9/6/2016

2. Modules, Scripts, and I/O. Quick Note on print. The Windchill Calculation. Script Mode. Motivating Script Mode 1/22/2016

Getting started with Java

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

2. Modules, Scripts, and I/O

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Lecture 2: Variables & Assignments

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Transcription:

CS 141, Lecture 3 Please login to the Math/Programming profile, and look for IDLE (3.4 or the unnumbered one are fine) <-- fine <-- fine <-- broken

Warmup: You are driving along an empty highway in South Carolina, keeping up with the flow of traffic, but going 74 miles-per-hour in a 60 miles-per-hour zone*. Assume that the fine is $15 for every mile per hour over the limit. Discuss with the person sitting next to you which of the following programs correctly prints your fine. * This in no way reflects any recent events that have happened to your professor.

You are caught going 74 miles/hour in a 60 miles/hour zone. The fine is $15 for every mile per hour over the limit. Which of the following programs correctly prints your fine? speed = 74 limit = 60 print(fine) fine = (speed limit) * 15 speed = 74 limit = 60 fine = over * 15 over = (speed limit) print(fine) limit = 60 speed = 74 fine = (speed limit) * 15 print(fine)

Python Shell

Python Shell Runs single-line "mini-programs" Runs each line after you type it and press enter. Results of computations are automatically printed (displayed) back to you.

Longer Programs

Longer Programs Code doesn't run until you ask Python to run it. Each line executes in order, top to bottom, line by line. Lets you run the code over and over without retyping. Nothing is automatically printed; to do so you must call the print function.

Math + - * / ** à exponents // à integer division % à remainder Normal order of operations. Use parentheses to change order of operations.

Variables Variables are assigned values by using an assignment statement: The variables in this program are exam1, exam2, exam3, and total. variable = value

Print function In a "real program" (not the Python Shell), nothing is displayed when you run the program unless you ask. Use the print function to do so.

print(,,, ) Replace the blank spaces above with the name of a variable, or a math expression. You can print any number of things at once. Separate each thing you want to print with a comma. Each thing will be displayed with a space in between. If you want to print words, surround the words with double quotes.

x = 3 print(x) x = 6 print(x) Computer Memory Program Output

x = 3 print(x) x = 6 print(x) Computer Memory Name Value x 3 Program Output

x = 3 print(x) x = 6 print(x) Computer Memory Name Value x 3 Program Output 3

x = 3 print(x) x = 6 print(x) Computer Memory Name Value x 6 Program Output 3

x = 3 print(x) x = 6 print(x) Computer Memory Name Value x 6 Program Output 3 6

a = 4 b = 5 print(a, b) a = 3 b = a print(a, b) a = b + 1 a = a + 1 print(a, b) a = 1 b = 2 a = b b = a print(a, b)

Variable names must be all one word (no spaces). Must consist of letters, numbers, or _. Start with a letter. Choose a name that indicates the meaning of the variable. For your grade on an exam: good ideas: exam, exam_score, grade, Bad ideas: e, g, the_score_i_got_on_the_exam

You're working at a fast food restaurant where a burger costs $3.99 and French fries cost $1.99. Write a program (in a separate file, saved as burger.py) that uses two variables to store these two prices. Your program should then print out the cost of buying two burgers and three orders of fries. If you finish early, make your program add in 9.25% sales tax.

Data types Integers (int) Whole numbers; may be negative. Floating point numbers (float) Any number with a decimal point; may be negative. Strings Any sequence of letters, numbers, or punctuation. String literals are always surrounded by quotation marks, single or double.

Input from the keyboard Use a variation of a variable assignment: For integers: variable = int(input("prompt")) For floats: variable = float(input("prompt")) For strings: variable = input("prompt")

You're working at a fast food restaurant where a burger costs $3.99 and French fries cost $1.99. Write a program (in a separate file, saved as burger.py) that uses two variables to store these two prices. CHANGE: Make your program ask the user for how many burgers and orders of fries they want, and print the total cost. If you finish early, make your program ask the user for the costs of a burger and fries, and the sales tax rate.