“If you can’t write it down in English, you can’t code it.”

Slides:



Advertisements
Similar presentations
CSci 1130 Intro to Programming in Java
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
CMT Programming Software Applications
Introduction to Computers and Programming - Class 2 1 Introduction to Computers and Programming Class 2 Introduction to C Professor Avi Rosenfeld.
Introduction to Python
Introduction to C Programming
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
Basic Input/Output and Variables Ethan Cerami New York
String Escape Sequences
Basic Elements of C++ Chapter 2.
A First Book of ANSI C Fourth Edition
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
2440: 211 Interactive Web Programming Expressions & Operators.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Chapter 2: Java Fundamentals
Week 1 Algorithmization and Programming Languages.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
CS346 Javascript -3 Module 3 JavaScript Variables.
Variables, Expressions and Statements
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Python Let’s get started!.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
CSCI 1100/1202 January 14, Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
A Sample Program #include using namespace std; int main(void) { cout
Introduction to Python Lesson 2a Print and Types.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
C++ First Steps.
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
Chapter 6 JavaScript: Introduction to Scripting
Python: Experiencing IDLE, writing simple programs
Chapter 2 Introduction to C++ Programming
Python Let’s get started!.
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Basic Elements of C++.
Revision Lecture
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 2 Applications and Data.
Basic Elements of C++ Chapter 2.
Escape Sequences What if we wanted to print the quote character?
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Introduction to C++ Programming
Rocky K. C. Chang September 18, 2018 (Based on Zelle and Dierbach)
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Beginning Python Programming
Unit 3: Variables in Java
Instructor: Alexander Stoytchev
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

“If you can’t write it down in English, you can’t code it.” Python Basics Output to the Screen Variables Arithmetic Operators “If you can’t write it down in English, you can’t code it.” -- Peter Halpern

Output: print() function Quotes are used to identify the text to be printed Double or single quotes print('hello, world!') prints, then goes to next line print("hello", "world") prints hello world (separated by space), then goes to next line

Output: Escape Sequences Two character sequences that represent other characters: \n: the new line escape sequence (like hitting return) \t: the tab escape sequence (like hitting tab) \": double quote (print " instead of beginning or ending a string) \': single quote \\: backslash

Output: Examples i = 5 #1 print(i) #2 print("i") #3 print(i, i) #4

Output:Examples print( "Hello, World!") #1 print ('Hello, World!') #2 print ("Hello, \nWorld!") #3 print ("\"Hello, World!\"") #4 print(' "Hello, World!" ') #5

Example Program #*************************************** # File: Camus.py # Author: Mary Eberlein # # A simple first Python program #*************************************** # print a Camus quote def main():     print ("Camus said:")  # print text and then go to next line     # The escape sequence \n does a carriage return.     # If we want to include double quotes in the text we are displaying, we can     # enclose the text in single quotes.     print (' "Some people talk in their sleep. \nLecturers talk while other people sleep." ')     main() Output Camus said: "Some people talk in their sleep. Lecturers talk while other people sleep."

Variables: What are they? A word/letter/phrase that represents a value Denotes memory location where value is stored Examples: placeholders in our algorithms i = 5

Variables: How are they used? Gives us the ability to refer to a value without knowing what it is Values are assigned to variables i = 5 Variables store a value A variable can hold different types of values (but only one value at a time) Python is untyped

Variables: What can we name them? Variable names are identifiers Must start with letter or underscore (_) Can be followed by any number of letters, underscores, digits Are case-sensitive (score is different from Score) Must avoid reserved words (e.g., def) Follow naming conventions

Reserved Words Special identifiers that are reserved for a special purpose in Python Examples: def, for, print, main Show up in color in IDLE

Variables: Naming Conventions Choose meaningful names max rather than m currentItem or current_item rather than c Variables should begin with a lowercase letter

Variable Names: Question What is a good and legal name for a variable? m Maximum 2max max

Arithmetic Operators: What are they? Operators that do arithmetic! (ha) +, -, *, /, % Perform mathematical operations using: Values referenced by variables (sum1 + sum2) Numerical literals (2 + 3) Both (sum1 + 2)

Arithmetic Operators: How do they work? Precedence same as math: () ** *, /, % +, - Evaluated from left to right When in doubt, use parentheses % indicates remainder from division

Arithmetic Operators: Math Example 15 + 2 3 – 1 15 % 2 25 % 5 2 ** 3

More Arithmetic Operators result = 2 * ((16-4)/2) result = 13 % 2 – 1 result = 4 result = result + 1 result = 17%3*4 result = result - 6

Arithmetic: Question What is the final value of i? i = 3 i = i + 5 3 5 8 12