Essential Question: How can I parse strings in python?
Mastery Objectives:
SWBAT to use parsing tools in python.
SWBAT compare strings using loops and indexes.
Do Now: Write a program that creates the list, myList, with 6 strings of the names of students in the class. Use a loop to print out the first letter of each name.
Do Now 2:
Write a Python program to create all possible strings by using 'a', 'e', 'i', 'o', 'u'. Use the characters exactly once.
Directions: Recreate the cooney program. Look through the parsing tools on the w3 schools website and modify the if statement that compares the characters in the string to create a new game. As a class, we will present the program to the class and the class will try to figure out your game. Make sure to change the intro of the code with hints so students can figure out the game.
count() Returns the number of times a specified value occurs in a string
endswith() Returns true if the string ends with the specified value
find() Searches the string for a specified value and returns the position of where it was found
index() Searches the string for a specified value and returns the position of where it was found
if intGuessSize %2 ==0: - only likes things with even number of letters
if strGuess[1] == 'a': - only likes things that have the letter 'a' in the second position
if strGuess.endswith('s'): - only likes things that end in the letter 's'
if strGuess.count('e') ==4: - only likes things that have 4 letters
if strGuess.find('e')==True: - only likes things that have the letter 'e' in it
if strGuess.index('s') ==4: - only likes things where the first 's' in the word is in the 5th position
if strGuess[i]=='e': - checks if the string contains 'e'.
if strGuess.startswith('s'): - only likes things that start with 's'
if "e" in strGuess: - only likes things with the letter 'e'
if 'e' not in strGuess: - only likes things without the letter 'e'
Ticket-to-Leave: Revise your project, don't tell anyone, so that your classmates won't understand your code. We are going to present this to the class.
Ticket-to-leave 2: Write code to check if a word has the first letter of your first name or last name. Put your answer in the comments.