More String Manipulation. Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function.

Slides:



Advertisements
Similar presentations
Java Programming Strings Chapter 7.
Advertisements

Lecture 03 – Sequences of data.  At the end of this lecture, students should be able to:  Define and use functions  Import functions from modules 
Chapter 8 Characters and Strings Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
 2007 Pearson Education, Inc. All rights reserved C Characters and Strings.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Hands on Projects Dr. Bernard Chen Ph.D. University of Central Arkansas July 9 th 2012
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
STRINGS CMSC 201 – Lab 3. Overview Objectives for today's lab:  Obtain experience using strings in Python, including looping over characters in strings.
CS151 Introduction to Digital Design
Strings CS303E: Elements of Computers and Programming.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
1 Fencepost loops suggested reading: The fencepost problem Problem: Write a static method named printNumbers that prints each number from 1 to a.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
1 Ordinal types An ordinal data type is an ordered set in which every element, except the first element, has an immediate predecessor, and every element,
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 7: Arrays.
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
Decision Structures, String Comparison, Nested Structures
 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.
Lists COMPSCI 105 S Principles of Computer Science.
Formatting Output. Line Endings By now, you’ve noticed that the print( ) function will automatically print out a new line after passing all of the arguments.
Python Let’s get started!.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Characters and Strings
Exception Handling and String Manipulation. Exceptions An exception is an error that causes a program to halt while it’s running In other words, it something.
Last of String Manipulation. Programming Challenge: Usernames Let’s say you work at the IT department for NYU and you are asked to generate student ID’s.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
CSC 162 Visual Basic I Programming. String Functions LTrim( string ) –Removes leading spaces from the left side of string RTrim( string ) –Removes trailing.
Last of String Manipulation. Programming Challenge Write a program that asks the user for a string and encodes it by the following guidelines: –If the.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Random Functions Selection Structure Comparison Operators Logical Operator
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
Characters must also be encoded in binary. ASCII maps characters to numbers.
1.4 Representation of data in computer systems Character.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
String and Lists Dr. José M. Reyes Álamo.
String Manipulation Part 1
String Methods Programming Guides.
Python Let’s get started!.
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Formatting Output.
More on Lists.
Strings Part 1 Taken from notes by Dr. Neil Moore
Representing Characters
Decision Structures, String Comparison, Nested Structures
String Manipulation Part 2
Decision Structures, String Comparison, Nested Structures
Manipulating Characters
String Encodings and Penny Math
Let’s get some practice!
CEV208 Computer Programming
String and Lists Dr. José M. Reyes Álamo.
Rocky K. C. Chang September 18, 2018 (Based on Zelle and Dierbach)
Chapter 3 Mathematical Functions, Strings, and Objects
Microsoft Visual Basic 2005: Reloaded Second Edition
CHAPTER 3: String And Numeric Data In Python
functions: argument, return value
15-110: Principles of Computing
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Introduction to Computer Science
String Encodings and Penny Math
Python Strings.
Formatting Output.
C Characters and Strings
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
Presentation transcript:

More String Manipulation

Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function return the number of times you find the specified character within the string literal. Then use the function to ask the user what character they would like to search for in a word / phrase and print out the result

Programming Challenge Write a program that counts the number of vowels found in a particular word / phrase Use your function from the previous challenge

Programming Challenge: Pig Latin In Pig Latin, the first letter of each word is removed and re-attached to the end of the string with the additional “ay” Create a function that converts words into Pig Latin Example: hello  ellohay

Programming Challenge: Mirror Write a function entitled “mirror” that reverses a word and returns it back to the user

Programming Challenge: RACECAR A palindrome is a word that when spelled backwards is still the same word Write a program that asks the user for a word Determine whether the word is a palindrome

ASCII Values Recall that to your computer, all characters are a combination of one’s and zero’s which can represent a numerical decimal point value and in return represent a letter Ex: “A” = 65 Python has a function to retrieve that numerical value for any characters

ASCII Values We can use the ord() function to do this The ord() function takes one argument, a single character as a string (in delimiters) Then, it returns an integer value from the ASCII table which represents that specific character

ASCII Values Just remember that because the function returns a value, it must have a place to return it to Example: value = ord(“A”) print(value) >> 65

Practice Write a program that asks the user for a word, or any string Then print out the string, one character at a time with it’s associated ASCII value Give me a name: Donald >> D = 68 o = 111 n = 110 a = 97 l = 108 d = 100

ASCII Values We can reverse this process and turn integer values into string characters by using the chr() function The chr() function takes one integer argument and returns it’s character equivalent from the ASCII table as a string Example: x = chr(65) print(x) >> A

Programming Challenge Write a program that generates a random password for the user Passwords must include: – At least 10 characters – Uppercase AND lowercase letters – At least one number

Programming Challenge Write a program that asks the user for a string and encodes it by the following guidelines: –If the letter is a vowel, leave it –For any other letter, add one to it’s value (i.e. “a” is “b”)