Input and Output CMSC 120: Visualizing Information Lecture 4/10.

Slides:



Advertisements
Similar presentations
WALT: Know the months of the year poem. Answer questions about the months.
Advertisements

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Introduction to Programming Lecture 34. In Today’s Lecture Arrays of objects Arrays of objects Interaction of Arrays with Free Store Interaction of Arrays.
Adapted from John Zelle’s Book Slides
Python Programming: An Introduction to Computer Science
Chubaka Producciones Presenta :.
2012 JANUARY Sun Mon Tue Wed Thu Fri Sat
January 2012 Monday Tuesday Wednesday Thursday Friday Sat/ Sun / /8 14/15 21/22 28/
P Pathophysiology Calendar. SundayMondayTuesdayWednesdayThursdayFridaySaturday January 2012.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Chicas, este calendario si es pa' nosotras !!!!!.
Computing with Strings CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSAT/SUN Note: You can print this template to use as a wall calendar. You can also copy the slide for any month to add.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
2007 Monthly Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSAT/SUN Note: You can print this template to use as a wall calendar. You can also copy the slide for any month to add.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
CSC 110 Sequences: Strings, Lists, and Files [Reading: chapter 5] CSC 110 F 1.
CS190/295 Programming in Python for Life Sciences: Lecture 3 Instructor: Xiaohui Xie University of California, Irvine.
Computer Science 101 Introduction to Programming.
Strings CS303E: Elements of Computers and Programming.
WORD JUMBLE. Months of the year Word in jumbled form e r r f b u y a Word in jumbled form e r r f b u y a february Click for the answer Next Question.
DATE POWER 2 INCOME JANUARY 100member X 25.00P2, FEBRUARY 200member X 25.00P5, MARCH 400member X 25.00P10, APRIL 800member.
Months of the year. jANUARY New year’s day fEBRUARY Valentine’s day.
Calendar for 2011 Months of the Year with Holidays.
2011 Calendar Important Dates/Events/Homework. SunSatFriThursWedTuesMon January
Formatted Output CSE 1310 – Introduction to Computers and Programming 1.
TEMPORAL VISUALIZATION OF DATA FROM THE FRENCH SENTINEL NETWORK.
July 2007 SundayMondayTuesdayWednesdayThursdayFridaySaturday
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
File Processing CMSC 120: Visualizing Information Lecture 4/15/08.
Python Programming, 3/e1 Python Programming: An Introduction to Computer Science Chapter 5 Sequences: Strings, Lists, and Files.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
Python Programming: An Introduction to Computer Science
Python: Sequences: Strings, Lists and files (Part II)
Dictation practice 2nd Form Ms. Micaela-Ms. Verónica.
Binary Files.
TIMELINES PHOTOS This is an example text
TIMELINES PHOTOS This is an example text
McDonald’s Kalender 2009.
McDonald’s Kalender 2009.
13-block rotation schedule
2017/18 Payment Calendar Due Date Cut-off Day 1st of every month
McDonald’s Kalender 2009.
0845 Analysis I have only very recently taken over responsibility for the 0845 number and whilst questions were asked of Derrick some months ago, we have.
Problem Gambling Clicks to Opgr.org
2300 (11PM) September 21 Blue line is meridian..
CS190/295 Programming in Python for Life Sciences: Lecture 3
過故人莊 ~孟浩然 故人具雞黍,邀我至田家。 綠樹村邊合,青山郭外斜。 開軒面場圃,把酒話桑麻。 待到重陽日,還來就菊花。
McDonald’s calendar 2007.
15-110: Principles of Computing
Teacher name August phone: Enter text here.
CHAPTER 4: Lists, Tuples and Dictionaries
Circle Chart Template Process Name.
February 2007 Note: Source:.
January 2015 Sunday Monday Tuesday Wednesday Thursday Friday Saturday
MONTHS OF THE YEAR January February April March June May July August
Sequences: Strings, Lists, and Files
McDonald’s calendar 2007.
Production Month Sun Hours K Monthly Kwh Tou Peak Value After Kwh
E W ©
Habitat Changes and Fish Migration
2015 January February March April May June July August September
Habitat Changes and Fish Migration
E W ©
Class 8 setCoords Oval move Line cloning vs copying getMouse, getKey
Presentation transcript:

Input and Output CMSC 120: Visualizing Information Lecture 4/10

Computing Input Data Store Manipulate Data Output Data InputMemoryOutput CPU Types of Data Numbers Logic Objects Sequences Strings Types of Data Numbers Logic Objects Sequences Strings Input - Output Dynamic (User) Stored (Text File) Input - Output Dynamic (User) Stored (Text File)

Text string data type Sequence of characters 'my string'

Basic String Operations >>> 'spam' + 'eggs' 'spameggs' >>> 3 * 'spam' 'spamspamspam ' >>> (3 * 'spam') + (5 * 'eggs') 'spamspamspameggseggseggseggseggs' >>> len('spam') 4 >>> for ch in 'Spam!' print ch S p a m !

Basic String Operations >>> breakfast = 'SpamAndEggs' >>> breakfast[0] >>> breakfast[4:7] >>> breakfast[-2] >>> breakfast[:] >>> breakfast[:4] >>> breakfast[4:]

Basic String Operations OperatorMeaning + Concatenation * Repetition [] Indexing [:] Slice len( ) Length for in Iteration through characters

String Representation Numbers: Stored in binary notation Computer CPU circuitry designed to manipulate 0s and 1s Text: Encoded as numbers ASCII (American Standard): A-Z = a-z = Unicode

String Representation Switching from character to encoded ordinal >>> ord('a') 97 >>> ord('A') 65 >>> chr(97) 97

Interactive Input and Output >>> fname = input('Enter name: ') Enter name: 'Emily' >>> print 'Hello', fname Hello Emily

Raw Input >>> fname = input('Enter name: ') Enter name: Emily Traceback (most recent call last): File " ", line 1, in input('Enter name: ') File " ", line 1, in NameError: name 'Emily' is not defined

raw_input >>> fname = raw_input('Enter name: ') Enter name: Emily raw_input Exactly like input, except... it does not evaluate the expression input is treated like a string of text >>> print 'Hello', fname Hello Emily

raw_input >>> fname = raw_input('Enter name: ') Enter name: 5 >>> fname '5' >>> fname = raw_input('Enter name: ') Enter name: Emily Allen fname 'Emily Allen' String Processing: translating raw input strings into appropriate types of data

Simple String Processing # generate a user name def main(): first = raw_input('Enter first name: ') last = raw_input('Enter last name: ') # concatenate first initial with # 7 characters of the last name uname = first[0] + last[:7] print uname main() emily greenfest egreenfe

Simple String Processing # generate a user name def main(): first = raw_input('Enter first name: ') last = raw_input('Enter last name: ') # concatenate first initial with # 7 characters of the last name uname = first[0] + last[:7] print User name is: uname main() Enter first name: emily Enter last name: greenfest User name is: egreenfe

Simple String Processing Strings are objects! >>> myName = raw_input('Enter whole name: ') Enter whole name: Emily Greenfest-Allen >>> myName 'Emily Greenfest-Allen' >>> myName.split() ['Emily', 'Greenfest-Allen'] >>> myName.split('-' ) ['Emily Greenfest', 'Allen']

Simple String Processing >>> s = 'Spam and Eggs' >>> s.capitalize() 'Spam and eggs' >>> s.capwords() 'Spam And Eggs' >>> s.upper() 'SPAM AND EGGS' >>> s.lower () 'spam and eggs'

Simple String Processing >>> s = 'Spam and Eggs' >>> s.replace('and','or') 'Spam or Eggs' >>> s.count('a') 2 >>> s.find('E') 9

Input/Output String Maninpulation

Date Conversion User enters a date in mm/dd/yyyy format ( dateStr ) Split dateStr into month, day, and year strings Convert the month string into a month number Use the month to look up the month name Create a new date string in form Month Day, Year Output new date string

Date Conversion # User enters a date in mm/dd/yyyy format (dateStr) dateStr = raw_input('Enter date (mm/dd/ yyyy): ') # Split dateStr into month, day, and year strings monthStr, dayStr, yearStr = dateStr.split('/') Enter date (mm/dd/ yyyy): 05/07/1977 >>> print monthStr, dayStr, yearStr monthStr '05'

String Conversion >>> int('5') 5 >>> float('5') 5.0 >>> string(2.8) '2.8' >>> eval('5 + 2') 7

Date Conversion # convert month string to month name months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] monthName = months[int(monthStr) – 1] # output in form Month Day, Year print monthName, dayStr + ',', yearStr Enter date (mm/dd/ yyyy): 05/07/1977 May 7, 1977