String Encodings and Penny Math

Slides:



Advertisements
Similar presentations
Review Binary –Each digit place is a power of 2 –Any two state phenomenon can encode a binary number –The number of bits (digits) required directly relates.
Advertisements

The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Introduction to Computing Using Python Chapter 6  Encoding of String Characters  Randomness and Random Sampling.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Representing Nonnumeric Data Everything is really a number.
CATHERINE AND ANNIE Python: Part 4. Strings  Strings are interesting creatures. Although words are strings, anything contained within a set of quotes.
Chars and strings Jordi Cortadella Department of Computer Science.
Lab 07: Caesar Cypher Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
Lab 07: Caesar Cypher Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
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.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Advanced Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Dictionaries Intro to Computer Science CS 1510 Dr. Sarah Diesburg.
Thinking about programming Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Introduction to Files Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Problem Solving Intro to Computer Science CS1510 Dr. Sarah Diesburg 1.
Intelligent Data Systems Lab. Department of Computer Science & Engineering Practices 컴퓨터의 개념 및 실습 4 월 11 일.
Numerical Representation Intro to Computer Science CS1510 Dr. Sarah Diesburg 1.
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Numerical Representation
Thinking about programming
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Breaking the Code Can anyone guess the phrase from this “code”?
Data Encoding Characters.
Representing Nonnumeric Data
Thinking about programming
Intro to Computer Science CS1510
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Numerical Representation
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
More Nested Loops and Lab 5
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lists – Indexing and Sorting
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Types, Truth, and Expressions (Part 2)
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Thinking about Strings
COMS 161 Introduction to Computing
COMS 161 Introduction to Computing
Lists – Indexing and Sorting
Intro to Nested Looping
Numerical Representation
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
functions: argument, return value
Intro to Computer Science CS1510 Dr. Sarah Diesburg
The Data Element.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lists – Indexing and Sorting
String Encodings and Penny Math
The Data Element.
Types, Truth, and Expressions
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Types, Truth, and Expressions (Part 2)
Numerical Representation
Presentation transcript:

String Encodings and Penny Math Intro to Computer Science CS1510 Dr. Sarah Diesburg

Questions about PA05?

String Encodings There are two systems for representing characters: ASCII and Unicode ASCII takes the English letters, numbers and punctuation marks and associates them with an integer number

String Encodings We can get the encodings from characters using the ord function >>> ord(‘x’) Humans can look this number up in the ASCII table We can get the characters back from the encoding using the chr function >>>chr(120)

Comparisons Within Sequence It makes sense to compare within a sequence (lower case, upper case, digits). ‘a’ < ‘b’ True ‘A’ < ‘B’ True ‘1’ < ‘9’ True Now comparisons make sense, because we are really comparing the ord() encodings of each character

Penny Math Penny Math is a simple formula Thus A (or a) costs 1 penny B (or b) costs 2 pennies … Z (or z) costs 26 pennies Everything else is FREE Thus “Sarah” costs 19+1+18+1+8=47 cents “Diesburg” costs 4+9+5+19+2+21+18+7=85 cents “Sarah Diesburg!!!” costs 47+85=132 cents, or $1.32 “@#$!!” is free

Our next task Write a script called pennyMath that reads in a String and prints the integer value corresponding to the “cost” of the String.