Comparing Strings – How to

Slides:



Advertisements
Similar presentations
Hand speed 1.He should move his hand up and down more quickly 2.He should move his hand up and down more slowly 3.Neither (1) nor (2) will change the time.
Advertisements

CREATING a HUFFMAN CODE EVERY EGG IS GREEN E ///// V/V/ R // Y/Y/ I/I/ S/S/ N/N/ Sp /// V/V/ Y/Y/ I/I/ S/S/ N/N/ R // Sp /// G /// E /////
CSCI 51 Introduction to Programming Dr. Joshua Stough February 10, 2009.
Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …
Fall 2004COMP 3351 Undecidable problems for Recursively enumerable languages continued…
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
מבנה מחשב תרגול 2 ייצוג תווים בחומרה. A programmer that doesn’t care about characters encoding in not much better than a medical doctor who doesn’t believe.
Practice for Midterm 1. Practice problems These slides have six programming problems for in-class practice There are an additional seven programming problems.
ASCII and Unicode. ASCII Inside a computer, EVERYTHING is a number – that includes music, sound, and text. In the early days of computers, every manufacturer.
Decisions in Python Comparing Strings – ASCII History.
Structure of program You must start with a module import# You must then encapsulate any while loop in a main function at the start of the program Then.
Multiplication properties. Multiplication properties.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Decision Structures and Boolean Logic
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?
Decisions in Python Bools and simple if statements.
Title/Scene one About my first scene My first scene is meeting the family, the family are outside walking to the town. I used a motion tween to move.
Python Selection. All the programs you have been developing so far have been sequential, this means that each instruction is executed in a set order.
Characters and Strings. Characters  New primitive char  char letter; letter = ‘a’; char letter2 = ‘C’;  Because computers can only represent numbers,
Decision Structures, String Comparison, Nested Structures
Sequencing The most simple type of program uses sequencing, a set of instructions carried out one after another. Start End Display “Computer” Display “Science”
 How do you represent a number with no value?  Mathematicians defined the “number” 0 (zero)  How do we represent a string with no value?  Use an empty.
Strings The Basics. Strings a collection data type can refer to a string variable as one variable or as many different components (characters) string.
Properties of Addition and Multiplication. Distributive Property A(B + C) = AB + BC 4(3 + 5) = 4x3 + 4x5.
CSCE 3110 Data Structures & Algorithm Analysis Rada Mihalcea Trees Applications.
Visual C++ Programming: Concepts and Projects Chapter 8A: Binary Search (Concepts)
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.
1 Huffman Codes. 2 ASCII use same size encoding for all characters. Variable length codes can produce shorter messages than fixed length codes Huffman.
Selection in C++ If statements. Control Structures Sequence Selection Repetition Module.
Bellringer. Properties of Real Numbers Properties There are several properties of real numbers that we use each day. They are: 1. Commutative 2. Associative.
GCSE COMPUTER SCIENCE Practical Programming using Python
Discussion 4 eecs 183 Hannah Westra.
Huffman Codes ASCII is a fixed length 7 bit code that uses the same number of bits to define each character regardless of how frequently it occurs. Huffman.
CSCE 3110 Data Structures & Algorithm Analysis
Assignment 6: Huffman Code Generation
Unit 5 Lesson 6: User Input and Strings
Debugging and Random Numbers
Python 6 Mr. Husch.
LESSON 5 Learning Objective 1 Learning Objective 2 Did you know….?
Network Programming (3)
Topics The if Statement The if-else Statement Comparing Strings
String Manipulation.
Python Lesson 6 Mr. Kalmes.
Decision Structures, String Comparison, Nested Structures
Topics The if Statement The if-else Statement Comparing Strings
Python 17 Mr. Husch.
How to develop a program
Sequential and Random access of elements
Decision Structures, String Comparison, Nested Structures
Lesson 6: User Input and Strings
Selection (IF Statements)
Coding Concepts (Data- Types)
Using Text Files in Python
Selection Statements.
مديريت موثر جلسات Running a Meeting that Works
Comparing Strings Strings can be compared using the == and != operators String comparisons are case sensitive Strings can be compared using >, =, and.
Python 17 Mr. Husch.
Appending or adding to a file using python
Introduction to Computer Science
Lab 3: File Permissions.
Decidability continued….
Understanding Variables
Python Inputs Mr. Husch.
Python 8 Mr. Husch.
Nate Brunelle Today: Style, Collections
Activity 2 How is the word length of a two’s complement representation changed without affecting its value? In this activity, we are going to study how.
COMPUTING.
P8.py.
Presentation transcript:

Comparing Strings – How to Decisions in Python Comparing Strings – How to

How to compare strings Start with the first (leftmost) characters in the two strings While they are the same and strings have not run out, move to the next characters to the right in each string If both strings ran out at the same time, they are equal Otherwise if one string is shorter than the other (only one ran out) and they are identical up to the length of the shorter, the shorter string is the lesser string Otherwise the characters are different, decide based on their ASCII codes – doesn’t matter what the rest of the strings are, this difference is the deciding point