Course A201: Introduction to Programming 09/09/2010.

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

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
 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.
Variables and I/O. Types Strings –Enclosed in quotation marks –“Hello, World!” Integers –4, 3, 5, 65 Floats –4.5, 0.7 What about “56”?
Introduction to Python
 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
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
Basic Elements of C++ Chapter 2.
Guide to Programming with Python Chapter Two Basic data types, Variables, and Simple I/O: The Useless Trivia Program.
Expressions, Data Conversion, and Input
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Bell Ringer What types are numbers are there is the python programming language?
Course A201: Introduction to Programming 09/09/2010.
Introduction to Python
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Input, Output, and Processing
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
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.
Python Conditionals chapter 5
Course A201: Introduction to Programming 09/30/2010.
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
INPUT & VARIABLES.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
Modularity using Functions Chapter 4. Modularity In programming blocks of code often can be "called up" and reused whenever necessary, for example code.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
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,
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
Chapter 02 (Part II) Introduction to C++ Programming.
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.
Topics Designing a Program Input, Processing, and Output
Introduction to Python
Data Types and Conversions, Input from the Keyboard
2.5 Another Java Application: Adding Integers
Variables, Expressions, and IO
Formatting Output.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
MSIS 655 Advanced Business Applications Programming
Chapter 2 - Introduction to C Programming
Topics Designing a Program Input, Processing, and Output
Conversion Check your class notes and given examples at class.
Topics Designing a Program Input, Processing, and Output
CS150 Introduction to Computer Science 1
Data Types and Expressions
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2 - Introduction to C Programming
Unit 3: Variables in Java
Data Types and Maths Programming Guides.
Introduction to C Programming
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

Course A201: Introduction to Programming 09/09/2010

Recap [variable] – a name that carries/represents some value – You should give them values, before you use them because IDLE does not know what it is and what value it carries ex: service_rate = ‘good’ tip_percent = 0.15

Recap [types] integer – ex: 1; 3; 999; 8019 floating point (float) – ex: 0.8; ; String – ex: “Hi”, “you name is: ”,

Recap [types] string: – consists of characters(letters, numbers, anything you can type in from keyboard) – always within single/double quotes – escape sequences: using back slash – ex: ‘good’; “Please enter: ”; ‘ ’

Recap [types] string: – strings cannot be convert or compared to integers/floats unless they only contains numbers and are converted using type conversion functions – Ex: float(service) -> ERROR! Ex: ‘1’ == 1, result is False Ex: a = ‘1’; a + 2 -> ERROR!

Recap Type conversion functions: int(), str(), float() Variables/Values on both side of “+”(concatenation) should be in the same type Ex: num1 = 2, num2 = 3 “Sum of ” + num2 + “ and ” + num2 -> ERROR! “Sum of ” + str(num2) + “ and ” + str(num2) Be careful about logical errors

Recap [functions] I am a function. I will perform a certain job. input1, input2, input3, … output1, output2, output3, … You give me some inputs I give you some outputs back, explicitly or implicitly

Recap [functions: print] print: output things on the screen – Ex: date = ‘Sep. 23th’ print(‘Today is’, date) – All variables/values you put between parentheses are ARGUMENTS. (Important concept!!) Arguments are separated by comma ->, In the example above, you passes TWO arguments into the function print() Here

Recap [functions: print] print(“Sum of ” + num2 + “ and ” + num2) -> ERROR! print(“Sum of ”, num2, “ and ”, num2) -> CORRECT! – In the first line, the concatenation will be executed first, that’s when error happens. Variables/values on both sides of + should be in the same type – In the second line, there are 3 commas. So, you actually passed 4 arguments into function print. Different arguments can be in different types.

Recap [functions: raw_input] raw_input: reads anything the user input from keyboard, and returns the value (store it in a variable you named) as a STRING – Ex: service_rate = raw_input(‘Please enter the service rate: ’) After this, no matter what the user entered, service_rate would be a string. It is a prompt message

Recap [Arithmetic operations] – % : called modulo/modulus, returns remainder – / : division – // : floor division, returns the quotient – ** : exponent, 2**3 is 8 Due to version conflict, the safest way to perform any division, convert the integers to floating numbers first. a += 1 is short for a = a + 1

Have a nice weekend!