Intro to Python

RUF Advanced Class

bit.ly/rufpython1

Problem #1. Morse Code

We will provide you a dictionary that represents a simple substitution cipher. The dictionary is a mapping from a 5-symbol code to a single letter. Your task is to use this dictionary to decode an encrypted piece of text we provide. Download the dictionary from Github.

The format of the encoded text is groupings of five characters separated by spaces. For instance, if “abcde” corresponded to “h” and “zyxwv” corresponded to “i”, the encoding for “hi” would be “abcde zyxwv”

Bonus: if you find the above too easy, write a method to encrypt “plain” text with the same code

 

Problem #2. More Dictionaries

Write a function that, given two lists, one of keys and one of values, makes a dictionary of the key-value pairs that share the same index.  For instance, if the lists are

keys = ['one', 'two', 'three']

vales = [1, 2, 3]

the resulting dictionary should look like

{ 'one': 1, 'two': 2, 'three': 3 }

Call this function with lists such as the above keys and values and print out the resulting dictionary.

 

Problem #3. Looping Over Dictionaries

Santa has a dictionary of string-int key-value pairs, where each key is a kid's name and each value is their "goodness score."  Santa only gives presents to kids with a positive score. Write a function to iterate over the dictionary to count how many kids have positive scores to let Santa know how many presents his elves should make.  Print out that number.  Bonus: if any kids have negative scores, print out which kid has the most-negative score.

Example dictionary:

d = {

  'Harry': 500,

  'Ron': 450,

  'Draco': -325

}

With this example dictionary, 2 kids have positive scores. And for the bonus, Draco has the most-negative score.

 

Problem #4. Counting cards

Jeff Ma has started to count cards at the casino.  He has recorded which cards he has seen in cards.txt.

Make a dictionary that maps each suit to a set of numbers seen.  Read cards.txt to figure out which cards he has seen.  Each line in cards.txt will have a card's suit and number (1-13) e.g. Heart 12.  Once all cards have been read, figure out which cards Jeff hasn't yet seen so he can decide which play to make.  Print out the various cards he hasn't seen.

Hint: It may be useful to make a list of suits, such as SUITS = ['Spade', 'Club', 'Heart', 'Diamond']

 

Project: Store (Part 1)

For our project, we will be making a representation of a store.  For the first step in making our store, we want to greet our customer (perhaps with a randomly selected greeting out of a list of possible greetings?), display the items available for purchase, and ask the customer which item he would like to purchase.

An example of a list of store items is a selection of the food emojis, listed here: food.txt.  This list contains each item's emoji, full name, quantity in stock, and price, all of which can be displayed to the customer.  Feel free to use this list or to make your own.

Make it FUN 🥳

 

Project: Store (Part 2)

For part 2, we want to add functionality to our store.  Let's allow the customer to select which item he wants to purchase.  When the customer makes a selection, be sure to ask how much quantity he wants.  Then verify that the store has enough quantity to sell and that the customer has enough money to make the purchase.

Feel free to come up with additional functionality for the store.  Perhaps you allow the user to sell items to the store, like a pawn shop, and subsequently you can purchase the items back from the store.  Perhaps the store sells lottery tickets, whose winnings can be computed on the spot.  Or perhaps the store will give you a loan.  Be creative!