Class 25 — Wednesday March 23

More dictionaries


Look both ways


Agenda


To do


Examples


Problem grocery_items.py

Some program runs

dict_keys(['apple', 'broccoli', 'cheese', 'dijon', 'febreeze', 'eggplant'])

Enter which items you'd like to purchase, separated by spaces: apple broccoli cheese

Your total cost is $ 3.52

dict_keys(['apple', 'broccoli', 'cheese', 'dijon', 'febreeze', 'eggplant'])

Enter which items you'd like to purchase, separated by spaces: dijon eggplant febreeze

Your total cost is $ 7.67

dict_keys(['apple', 'broccoli', 'cheese', 'dijon', 'febreeze', 'eggplant'])

Enter which items you'd like to purchase, separated by spaces: dijon

Your total cost is $ 1.88



Problem yearly.py

Some program runs

Enter each TA's year in school.

What year is Nicki ?

2

What year is Rachel M ?

4

What year is Jimmy ?

3

What year is Amshala ?

2

What year is Kevin ?

3

What year is Meghan ?

4

What year is Grace ?

2

What year is Bailey ?

2

What year is Rachael C ?

3

What year is Miriam ?

3

What year is Mason ?

3

names2years = {'Nicki': 2, 'Rachel M': 4, 'Jimmy': 3, 'Amshala': 2, 'Kevin': 3, 'Meghan': 4, 'Grace': 2, 'Bailey': 2, 'Rachael C': 3, 'Miriam': 3, 'Mason': 3}

The average number of years of experience is 2.8181818181818183



Problem letter_counts.py

Some program runs

Enter word: Elizabeth

letters2counts = {'e': 2, 'l': 1, 'i': 1, 'z': 1, 'a': 1, 'b': 1, 't': 1, 'h': 1}

Enter word: banana

letters2counts = {'b': 1, 'a': 3, 'n': 2}



In-class Assignment: word_counts.py

Please submit the following code before the end of class today.

A program run

Enter sentence: Whatever will be will be

words2counts = {'whatever': 1, 'will': 2, 'be': 2}


 


  🦆 © 2022 Jim Cohoon   Resources from previous semesters are available.