Manipulating Characters

Slides:



Advertisements
Similar presentations
Representing Information as Bit Patterns
Advertisements

March 2006Taner Erig - EMU2-1 Metamorphosis of Information How is information represented and how do computers store information?
Computer Science 111 Fundamentals of Programming I Sequences: Strings.
© BYU 02 NUMBERS Page 1 ECEn 224 Binary Number Systems and Codes.
Decisions in Python Comparing Strings – ASCII History.
Manipulating Characters In today’s lesson we will look at: how text is stored inside the computer how we can use BASIC functions to manipulate and encipher.
Data Representation S2. This unit covers how the computer represents- Numbers Text Graphics Control.
Computer Structure & Architecture 7c - Data Representation.
CATHERINE AND ANNIE Python: Part 4. Strings  Strings are interesting creatures. Although words are strings, anything contained within a set of quotes.
Python Types Python values are of various “types” Ints, Floats, Strings, Characters, and more Two representations of numbers 1 vs 1.0.
What is a computer? A computer is a device that:
Manipulating Text In today’s lesson we will look at: why we might want to pick out parts of text strings some BASIC functions that can be used to chop.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
CISC1100: Binary Numbers Fall 2014, Dr. Zhang 1. Numeral System 2  A way for expressing numbers, using symbols in a consistent manner.  " 11 " can be.
Do it now activity Can you work out what the missing symbols are and work out the order they should be in if the table shows smallest to largest KB kilobyte.
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
Data Representation, Number Systems and Base Conversions
General Purpose Packages DATA TYPES. Data Types Computer store information in the form of data. Information has meaning. Eg 23 May 2005 Data has no meaning.
Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Strings The Basics. Strings a collection data type can refer to a string variable as one variable or as many different components (characters) string.
Data Representation.
1 Problem Solving using Computers “Data....Representation, and Storage.
Files in Python The Basics. Why use Files? Very small amounts of data – just hardcode them into the program A few pieces of data – ask the user to input.
More String Manipulation. Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function.
Number Systems. ASCII – American Standard Code for Information Interchange – Standard encoding scheme used to represent characters in binary format on.
Software Design and Development Storing Data Part 2 Text, sound and video Computing Science.
Data Representation. In our everyday lives, we communicate with each other using analogue data. This data takes the form of: Sound Images Letters Numbers.
1.4 Representation of data in computer systems Character.
Lecture Coding Schemes. Representing Data English language uses 26 symbols to represent an idea Different sets of bit patterns have been designed to represent.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
By the end of this session you should be able to... Understand character sets and why these are used within computer systems. Understand how characters.
Text and Images Key Revision Points.
GCSE COMPUTER SCIENCE Practical Programming using Python
Day 6 - Encoding and Sending Formatted Text
Storing Graphics Nat 5 Data Representation Lesson 4a: Storing Graphics
Chapter 8 & 11: Representing Information Digitally
Arithmetic Shifts and Character Representation
Week 3 - Wednesday CS 113.
Input and Output Upsorn Praphamontripong CS 1110
Number Representation
Day 6 - Encoding and Sending Formatted Text
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Data Transfer ASCII FILES.
Digital Electronics Jess 2008.
BTEC NCF Dip in Comp - Unit 02 Fundamentals of Computer Systems Lesson 10 - Text & Image Representation Mr C Johnston.
Breaking the Code Can anyone guess the phrase from this “code”?
Data Encoding Characters.
TOPICS Information Representation Characters and Images
Data Representation ASCII.
Folders out, planners out…
String Manipulation.
Class 9 Reading and writing to files chr, ord and Unicode
G7 programing language Teacher / Shamsa Hassan Alhassouni.
Computer Data Types Basics of Computing.
Lesson 6: User Input and Strings
Manipulating Text In today’s lesson we will look at:
“If you can’t write it down in English, you can’t code it.”
Presenting information as bit patterns
Digital Encodings.
Day 6 - Encoding and Sending Formatted Text
functions: argument, return value
Learning Intention I will learn how computers store text.
15-110: Principles of Computing
Introduction to Computer Science
Sequences Sequences are collections of data values that are ordered by position A string is a sequence of characters A list is a sequence of any Python.
Understanding Variables
WJEC GCSE Computer Science
C Programming Language
ASCII and Unicode.
Programming Techniques
Presentation transcript:

Manipulating Characters In today’s lesson we will look at: how text is stored inside the computer how we can use Python functions to manipulate and encipher text

How Is Text Stored? All types of data are stored inside the computer as numbers: for images, the number represents the colour of each pixel for sound, the number represents how loud the sound is for each fraction of a second for text, a numerical code is stored that represents each character The most common method for coding text on a PC is called ASCII – the American Standard Code for Information Interchange

ASCII Codes ASCII Symbol 32 (space) 48 64 @ 80 P 96 ` 112 p 33 ! 49 1 64 @ 80 P 96 ` 112 p 33 ! 49 1 65 A 81 Q 97 a 113 q 34 " 50 2 66 B 82 R 98 b 114 r 35 # 51 3 67 C 83 S 99 c 115 s 36 $ 52 4 68 D 84 T 100 d 116 t 37 % 53 5 69 E 85 U 101 e 117 u 38 & 54 6 70 F 86 V 102 f 118 v 39 ' 55 7 71 G 87 W 103 g 119 w 40 ( 56 8 72 H 88 X 104 h 120 x 41 ) 57 9 73 I 89 Y 105 i 121 y 42 * 58 : 74 J 90 Z 106 j 122 z 43 + 59 ; 75 K 91 [ 107 k 123 { 44 , 60 < 76 L 92 \ 108 l 124 | 45 - 61 = 77 M 93 ] 109 m 125 } 46 . 62 > 78 N 94 ^ 110 n 126 ~ 47 / 63 ? 79 O 95 _ 111 o 127 

The ORD Function The ord() function takes a character and returns the corresponding ASCII code. For example: print(ord(“A”)) print(ord(“Hello”[0])) The output of these two lines of code is 65 and 72 respectively.

The CHR Function The chr() function takes an ASCII code and returns the corresponding character. For example: print(chr(65)) print(chr(ord(“a”)-32) The output of these two lines of code is A in both cases.

Slicing Text A distinctive feature of Python is its ability to slice text: You can get a single character by using its position, e.g. “Hello”[0] gives H You can take a number of characters using two numbers, e.g. “Hello”[1:4] gives ell You can use negative numbers to work backwards from the end, e.g. “Hello”[-1] gives o If you miss out one of the numbers Python assumes it to be the end of the string, e.g. “Hello”[1:] gives ello and “Hello”[:-1] would give you Hell.

Combining the Techniques e.g. How would you capitalise a name? name = input("What is your name? ") if ord(name[0])>96: name = chr(ord(name[0])-32) + name[1:] print("Did you mean " + name + "?“) else: print("Hello " + name + ", nice to meet you!“) PS. I know it’s easier to use name.title()!