<jupyter_start><jupyter_text>1-2.4 Intro Python Strings: input, testing, formatting- input() - gathering user input  - print() formatting   - Quotes inside strings - Boolean string tests methods   - **String formatting methods**  - **Formatting string input()**  - **Boolean `in` keyword**  -----> Student will be able to- gather, store and use string `input()`  - format `print()` output  - test string characteristics  - **format string output**  - **search for a string in a string**    &nbsp; Concepts   String formatting methods[![view video](https://iajupyterprodblobs.blob.core.windows.net/imagecontainer/common/play_video.png)]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{"src":"http://jupyternootbookwams.streaming.mediaservices.windows.net/693e416c-ab73-4387-a0d2-5a47668ae4de/Unit1_Section2-4-String-Format_Methods.ism/manifest","type":"application/vnd.ms-sstr+xml"}],[{"src":"http://jupyternootbookwams.streaming.mediaservices.windows.net/693e416c-ab73-4387-a0d2-5a47668ae4de/Unit1_Section2-4-String-Format_Methods.vtt","srclang":"en","kind":"subtitles","label":"english"}])the following methods are applied to string objects- **.capitalize()** - capitalizes the first character of a string- **.lower()** - all characters of a string are made lowercase- **.upper()** - all characters of a string are made uppercase- **.swapcase()** - all characters of a string are made to switch case upper becomes lower and vice versa  - **.title()** - each 'word' separated by a space is capitalized  &nbsp; Examples   String Formatting Methods<jupyter_code>print("ms. Browning is in her office.".capitalize())
fav_color = "green"
print(fav_color.capitalize(), fav_color, fav_color,"and", fav_color.upper()+"!")<jupyter_output>Green green green and GREEN!<jupyter_text>&nbsp; Task 1: multi-part  [ ] format with `.capitalize(), .lower(), .upper(), .swapcase()`> **Note:** use **print()**<jupyter_code># [ ] get input for a variable, fav_food, that describes a favorite food
fav_food=input()
# [ ] display fav_food as ALL CAPS, used in a sentence
print(fav_food.upper())
# [ ] dispaly fav_food as all lower case, used in a sentence
print(fav_food.lower())

# [] display fav_food with swapped case, used in a sentence
print(fave_food.swapcase())

# [] display fav_food with capitalization, used in a sentence
print("My favorite food is",fav_food.capitalize())



fav_color = "Forest Green"
# [] display the fav_color variable as upper, lower, swapcase, and capitalize formatting in a single print() statement

print(fav_color.upper(),fav_color.lower(),fav_color.swapcase(),fav_color.capitalize())<jupyter_output>FOREST GREEN forest green fOREST gREEN Forest green<jupyter_text>&nbsp; Concepts Formatting string input()[![view video](https://iajupyterprodblobs.blob.core.windows.net/imagecontainer/common/play_video.png)]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{"src":"http://jupyternootbookwams.streaming.mediaservices.windows.net/460107d8-5d62-432e-924b-a3c779b2e5c5/Unit1_Section2-4-Input-String_Formatting.ism/manifest","type":"application/vnd.ms-sstr+xml"}],[{"src":"http://jupyternootbookwams.streaming.mediaservices.windows.net/460107d8-5d62-432e-924b-a3c779b2e5c5/Unit1_Section2-4-Input-String_Formatting.vtt","srclang":"en","kind":"subtitles","label":"english"}])When storing input, sometimes a specific format is needed and formatting is applied to the **`input()`** function> **Note:** this technique overwrites the original user input in the variable with the formatted value   Example<jupyter_code># review and run code - test a capitalized color input
fav_color = input('What is your favorite color?: ').lower()
print(fav_color)<jupyter_output>What is your favorite color?: blue
blue<jupyter_text>&nbsp; Task 2   [ ] format &nbsp; ` input()` with ` .upper()`<jupyter_code># [] input variable fav_color as upper
fav_color = input("color").upper()

# [] print fav_color
print(fav_color)<jupyter_output>colorred
RED<jupyter_text>&nbsp; Concepts   Boolean `in` keyword [![view video](https://iajupyterprodblobs.blob.core.windows.net/imagecontainer/common/play_video.png)]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{"src":"http://jupyternootbookwams.streaming.mediaservices.windows.net/ef7e8587-8ce6-48a4-9a2f-fb0a09db287f/Unit1_Section2-4-Boolean-in.ism/manifest","type":"application/vnd.ms-sstr+xml"}],[{"src":"http://jupyternootbookwams.streaming.mediaservices.windows.net/ef7e8587-8ce6-48a4-9a2f-fb0a09db287f/Unit1_Section2-4-Boolean-in.vtt","srclang":"en","kind":"subtitles","label":"english"}])the **`in`** keyword can be used as a simple search returning **`True`** or **`False`** indication if a string is included in a target sequence.   comparing strings is case sensitive`'Hello'` is not the same as `'hello'`    Examples<jupyter_code># review and run code to test if a string is to be found in another string
menu = "salad, pasta, sandwich, pizza, drinks, dessert"
print('pizza' in menu)
# review and run code to test case sensitive examples 
greeting = "Hello World!"
print("'hello' in greeting = ",'hello' in greeting)
print("'Hello' in greeting = ", 'Hello' in greeting)<jupyter_output>'hello' in greeting =  False
'Hello' in greeting =  True<jupyter_text>example below: **remove case sensitivity from a string comparison**<jupyter_code># review and run code to test removing case sensitivity from a string comparison
greeting = "Hello World!"
print("'hello' in greeting = ",'hello' in greeting)
print("'Hello' in greeting = ", 'Hello' in greeting)
print("'hello' in greeting if lower used = ", 'hello'.lower() in greeting.lower())<jupyter_output>'hello' in greeting =  False
'Hello' in greeting =  True
'hello' in greeting if lower used =  True<jupyter_text>&nbsp; Task 3: multi-part  **[ ] add code below** testing the **`menu`** string variable for `'pizza'`, `'soup'`, and `'dessert'` using keyword &nbsp; **`in`**- print each test on a separate line- print a description for each test &nbsp; (e.g. - "`Pizza in menu = True`")<jupyter_code># [] print 3 tests, with description text, testing the menu variable for 'pizza', 'soup' and 'dessert'
menu = "salad, pasta, sandwich, pizza, drinks, dessert"
print("Pizza in menu = ","pizza".lower() in menu.lower())
print("soup in menu = ","soup".lower() in menu.lower())
print("dessert in menu = ","dessert".lower() in menu.lower())<jupyter_output>Pizza in menu =  True
soup in menu =  False
dessert in menu =  True<jupyter_text>Program: What is on the menu [ ] Create a program where a user can check if an item is on the menu- store the user response in a variable menu_ask- use the menu from above and add some additional items- the program should be able to ignore case mismatch so that "hello" is found in "Hello World!"<jupyter_code># Create a program where the user supplies input to search the menu
menu = "salad, pasta, sandwich, pizza, drinks, dessert,cake,fries,burgers"
menu_ask = input("What are you looking for? ")
print(menu_ask,"is on menu = ",menu_ask.lower() in menu.lower())<jupyter_output>What are you looking for? salad
salad is on menu =  True<jupyter_text>[ ] Challenge: Add to the menu- print the current menu- get user input for add_item variable- new_menu use string addition to add add_item to menu- print the new_menutesting- add a cell below add menu- check if an item is on the menu, check for previous items and the item you added<jupyter_code># add to menu
print(menu)
add_item = input("Add item: ")
new_menu = menu + ", " + add_item
print(new_menu)


# Testing Add to Menu - create user input to search for an item on the new menu
menu_ask = input("What are you looking for? ")
print(menu_ask,"is on menu = ",menu_ask.lower() in menu.lower())<jupyter_output>What are you looking for? fruit
fruit is on menu =  False<jupyter_text>&nbsp; Task 4 Fix The Error<jupyter_code># [ ] fix the error
paint_colors = "red, blue, green, black, orange, pink"
print('Red in paint colors = ',"red".lower() in paint_colors.lower())<jupyter_output>Red in paint colors =  True
{'fraction_non_alphanumeric': 0.1354332638803775, 'fraction_numerical': 0.024267679862728275, 'mean_word_length': 5.771784232365145, 'pattern_counts': {'":': 18, '<': 31, '<?xml version=': 0, '>': 34, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '35643', 'license': 'MIT', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2632, 'n_words': 784, 'path': 'Python Absolute Beginner/Module_1_2.4_Absolute_Beginner.ipynb', 'repo_name': 'kmusgro1/pythonteachingcode', 'size': '8159'}