Bell Ringer What types are numbers are there is the python programming language?

Slides:



Advertisements
Similar presentations
Python Basics: Statements Expressions Loops Strings Functions.
Advertisements

Intro to Python Welcome to the Wonderful world of GIS programing!
CPS120: Introduction to Computer Science INPUT/OUTPUT.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
03 Data types1June Data types CE : Fundamental Programming Techniques.
Python November 14, Unit 7. Python Hello world, in class.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
The Class String. String Constants and Variables  There is no primitive type for strings in Java.  There is a class called String that can be used to.
Introduction to Python
Chapter 2 Writing Simple Programs
Computing with Strings CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
Guide to Programming with Python Chapter Two Basic data types, Variables, and Simple I/O: The Useless Trivia Program.
Basic Input - Output. Output functions  printf() – is a library function that displays information on-screen. The statement can display a simple text.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
AOIT Introduction to Programming Unit 3, Lesson 10 Advanced Sequence Manipulation Copyright © 2009–2012 National Academy Foundation. All rights reserved.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
Chapter 2 Elementary Programming
Chapter 2: Java Fundamentals
Week 1 Algorithmization and Programming Languages.
C++ Character Set It is set of Characters/digits/symbol which is valid in C++. Example – A-Z, (white space) C++ Character Set It is set of.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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.
Characters and Character Sets tMyn1 Characters and Character Sets The characters that can be used are the upper and lower case letters, A to Z and a to.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
Basics of Most C++ Programs // Programmer: Clayton Price date: 9/4/ // File: fahr2celc.cpp 03. // Purpose:
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 3 Mathematical Functions, Strings, and Objects.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
Strings in Python. Computers store text as strings GATTACA >>> s = "GATTACA" s Each of these are characters.
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
1 CSC 221: Introduction to Programming Fall 2011 Input & file processing  input vs. raw_input  files: input, output  opening & closing files  read(),
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
COMP 110: Spring Announcements Lab 1 due Wednesday at Noon Assignment 1 available on website Online drop date is today.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
CSCI 130 Basic Input and Output Chapter 9. The printf ( ) function Printf(“\nThe value of x is %d”, x); Displayed to screen (assume x = 12): –The value.
Keyboard and Screen I/O (Input/Output). Screen Output  System.out is an object that is part of the Java language. (Don’t worry yet about why there is.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
Course A201: Introduction to Programming 09/09/2010.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
C++ Basics Lecture 2.
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Introduction to Python
Variables, Expressions, and IO
Useful String Methods Cont…
OUTPUT STATEMENTS GC 201.
C Formatted Input / Output Review and Lab Assignments
Introduction to C++ Programming
Escape Sequences Some Java escape sequences: See Roses.java (page 68)
Chapter 3 Mathematical Functions, Strings, and Objects
Java Programming Language
Unit 3: Variables in Java
Python Strings.
GCSE Computing.
What We Want To Do User enters: Mary Smith
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Bell Ringer What types are numbers are there is the python programming language?

Objective: Converting data to other forms of data and inputting data Agenda Housekeeping/Bell ringer How to convert data and inputting data notes Programming assignments Wrap up

Escape Sequences \\Backslash. Prints one backslash. \’Single Quote. Prints a single quote. \”Double quote. Prints a double quote. \aBell. Sounds the bell system. \bBackspace. Moves cursor back one space. \nNewline. Moves cursor to beginning of next line. \t Horizontal tab. Moves cursor forward to tab.

String helpers: Concatenating ““ + “ “ print “cat” + “ dog” catdog

Repeating strings print “dog” * 10 Suppressing a new line print “How are you”, print “I am fine.”

Using functions to change data types: float to int Float() How to use it? a = 24 b = float (a) Print a Output 24 Print b Output 24.

How to do it? Float to intint() >>>c = 38.0 >>> d= int (c) >>>c 38.0 >>>d 38

One issue with float to int >>>e= >>>f= int(e) >>> print e >>>print f 54 The int() function always rounds down.

Changing string to float >>>a = “76.3” >>>b = float (a) >>>print a “76.3” >>>print b

Get type from program with type() >>>a = “44.2” >>> b = 44.2 >>>type (a) >>>type(b)

Of Course!! Remember Int and float can only be numbers!!!!!

Using Type Conversions In our Temp Conversion Program, you could have used: Celsius = float(5)/9 * (F-32) Or Celsius = 5/float(9) * (F-32)

Input function raw_input()Gets input from user >>>print “What is your name?” >>>someName= raw_input() >>>print “Hi!,” someName, “ what are you doing?”

Ends up with Enter your name: Henry Hi! Henry What are you doing?

Get question and answer on one line—use comma >>>print “Enter your name:”, >>>yourName=raw_input() Output: Enter your name: Harold

Can also use this for >>>print “My ”, >>>print “dog’s ”, >>>print “name ”, >>>print “is skipper.” Ouput: My dog’s name is Skipper.

Short cut for raw_input() prompts >>>youName = raw_input (“Enter your name: ”) Raw input function will print Enter your name

Inputting numbers >>>temperature_string =raw_input() >>>fahrenheit = float(temperature_string) Or shortcut: fahrenheit= float(raw input())

Example >>>print “Fahrenheit to Celsius Conversion Program.” >>>print “Type in a temperature(f): ”, >>>f= float(raw_input()) >>>celsius = (f-32)*5.0/9 >>>print “That is”, >>>print celsius, >>>print “degrees celsius.”

Input from the web >>>import urllib >>>file = urllib.urlopen( ge.txt) ge.txt >>>message = file.read() >>>print message (Need direct internet connection)

String methods upper ()Returns the uppercase version lower ()Returns lowercase version swapcase()Returns a new string where the case of each character switches capitalize()Returns a new string were the first letter is capitalized and the rest are lowercase. title()First letter of each word is capitalized

More string methods Strip()Returns a string where all the white space at the beginning and end is removed. Replace(old, new[.max]) Returns a string where occurrances of the string old are replaced with the sring new. The optional max limits the number of replacements.