ECS 15 Variables. Outline  Using IDLE  Building blocks of programs: Text Numbers Variables!  Writing a program  Running the program.

Slides:



Advertisements
Similar presentations
ARDUINO CLUB Session 1: C & An Introduction to Linux.
Advertisements

ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
16-May-15 Sudden Python Drinking from the Fire Hose.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Python November 14, Unit 7. Python Hello world, in class.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Introduction to C Programming
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Group practice in problem design and problem solving
Introduction to Python
Munster Programming Training
Introduction to Computational Linguistics Programming I.
Python Lesson Week 01. What we will accomplish today Install Python on your computer Using IDLE interactively to explore String Variables if/else while.
Programming in Python Part I Dr. Fatma Cemile Serçe Atılım University
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Sep 12, 2007Sprenkle - CS1111 Objectives Review  Linux  Why programming languages? Compiled vs. Interpreted Languages Programming in Python  Data types.
Representing numbers and Basic MATLAB 1. Representing numbers  numbers used by computers do not behave the same as numbers used in mathematics  e.g.,
1 CSC103: Introduction to Computer and Programming Lecture No 6.
CPS120: Introduction to Computer Science
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Variables and Expressions CMSC 201 Chang (rev )
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Variables, Expressions and Statements
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Python Let’s get started!.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
GCSE Computing: Programming GCSE Programming Remembering Python.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Thinking about programming Intro to Computer Science CS1510 Dr. Sarah Diesburg.
A Sample Program #include using namespace std; int main(void) { cout
 Prepared by: Eng. Maryam Adel Abdel-Hady
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Thinking about programming
Python Let’s get started!.
Data Types and Conversions, Input from the Keyboard
Chapter 2 - Introduction to C Programming
Variables, Expressions, and IO
Thinking about programming
Introduction to C++ October 2, 2017.
Chapter 2 - Introduction to C Programming
CS 100: Roadmap to Computing
What are variables? Using input()
A look at Python Programming Language 2018.
Other types of variables
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Unit 3: Variables in Java
Text Copyright (c) 2017 by Dr. E. Horvath
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Presentation transcript:

ECS 15 Variables

Outline  Using IDLE  Building blocks of programs: Text Numbers Variables!  Writing a program  Running the program

Starting up Python  From START menu, pick “all programs”, then Python  Pick the “IDLE” option

IDLE  IDLE is an interpreter  Can use it like a calculator  Responds to input line-by-line Important vocabulary word

Remainder  0,1,2,3… and -1,-2,-3…. are integers  7//3 is integer division  7/3 is floating point division (diff. in Python 3)  7%2 = ?  % gives the remainder when 7 is divided by 2  (7//2)*2 + (7%2) = 7

Floating point numbers  7.0, 2.0, , 7.34 – floating point numbers  7.0/2.0 = 3.5 – floating point division  7/2 =3.5  If either number is floating point, so is the answer – so 7.0/2 = 3.5  8.0/3.0 = 2.666…665?  Floating point arithmetic does NOT give exact results!

Why not?  Computer numbers have a fixed number of decimal places  Exact results with floating point numbers have an infinite number of decimal places: Example: 8.0/3.0 = …….

Variables  x = 2.0 –- x is a variable  This is called an assignment  Variable on left-hand side gets value on right-hand side.  Pronounce this “x gets 2.0” or “x becomes 2.0”  x = x+3.0 – “x gets x+3”, so now x=5.0

Variable Names  Legitimate names: Letter (upper & lower case), number, underscore Do not start with a number Ex: x, y, m1, m2,xysgfh, my_ID, my_age, myAge, etc. Python is case-sensitive! Python command in lower case.  Good names Easy to remember and to understand the meaning Not too long, not too short Ex: my_age, myAge, etc. Be consistent, e.g., underscore, capitalize

Errors  Lots of things you do will cause errors  Something Python doesn’t understand  y = y+3 – you ask it to give the value y+3 to y, but it doesn’t know what y is.  Variables don’t stand for “any old number” like they do in algebra; a variable is always supposed to have a specific value.

Python commands in IDLE  You can type any Python command into IDLE, and it does it immediately  In lower case.  print is a Python command  ‘a rose is a rose’ is a string  “9.0/7.0” is also a string, because it’s in quotes

Making a program  Do something more complicated  Remember and repeat a bunch of commands

A program  A program is a list of statements in a file  x=2.0 is a statement  Python executes the statements one by one

Your program 1  Uses print  Uses variables  Uses remainder operator  Please make sure your program runs!