Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "More String Manipulation. Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function."— Presentation transcript:

1 More String Manipulation

2 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

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

4 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

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

6 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

7 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

8 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

9 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

10 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

11 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

12 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

13 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”)


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

Similar presentations


Ads by Google