Please place your programs in seperate files named as described in the problem. Improperly named programs will not count. Turn in your files by placing them in the dropbox. Please be mindful of the late policy.
Correct | 80% |
Commented | 10% |
Attempted | 10% |
Modify your program from problem 2.1 so
that users can add their own sounds. Call it customFX.py
.
if
statement, use a dictionary to
store the sounds.new [name] [sound]
if they want to
make a new sound. See interaction below for example.Hint: You can use the split
method on the user input to
break it into the first part and the second part. You can then use
len
to see if the user included a number of times. You can
do this instead of the finding and slicing that you did in homework 2.
Hint: Make sure to initialize your dictionary OUTSIDE of the loop, or it will get reset every time through the loop.
Hint: The dictionary will be reset each time you run the program, so a sound that you enter during one run will not be there during the next run.
Hint: stop
and new
should not be in the
dictionary. They should be the only things left in the if
statement, and the sounds should happen in else
Hint: Use has_key
on the animal name before you try to
get it to make sure that you don't get a dictionary error.
Here is a new sample set of interactions. User text is in red
effect: cow
Moo!
effect: horse
Neigh!
effect: dog
Woof!
effect: cat
Meow!
effect: horse 5
Neigh! Neigh! Neigh! Neigh! Neigh!
effect: turtle
I don't know that effect!
effect: new turtle Crawl!
New effect turtle added
effect: turtle 3
Crawl! Crawl! Crawl!
effect: stop
Goodbye!
Create a program called cards.py
that deals hands of
cards.
import
s, define two lists:
suits = ['Spades', 'Clubs', 'Diamonds', 'Hearts']
values = ['Two', 'Three', 'Four', 'Five', 'Six']
values = values + ['Seven', 'Eight', 'Nine', 'Ten']
values = values + ['Jack', 'Queen', 'King', 'Ace']
generateDeck(numJokers)
that returns a
list of all possible cards, represented as tuples. Use nested for loops
to create the list. The first part of the list should look like this:
[('Two', 'Spades'), ('Three', 'Spades'),
. At the end of the
list, there should be numJokers
joker cards, each
represented by the tuple (None, 'Joker')
; there should be
able to be 0 jokers.shuffle
function from the random
module to shuffle the deck after it is generated. Be careful:
shuffle
changes the list in place and returns
None
.dealHand(deck, size)
that takes a
list of cards and returns two things: a hand with size cards from the
first size
cards in deck and the rest of the deck.printCard(card)
that prints
out a card like this: Ace of Spades
Joker
Hint: You can make an empty list like this:
deck = []
Hint: You can use the append
method of a list to add
new items to the end
Hint: Try to get it to work without shuffling first. It will be easier to tell if you are missing cards.
Here is a sample session:
Number of jokers? 0
Number of hands? 2
Number of cards in a hand? 4
*** Hand 1 ***
Seven of Clubs
Four of Diamonds
Five of Spades
Ace of Clubs
**************
*** Hand 2 ***
Ten of Spades
Eight of Clubs
Ace of Diamonds
Nine of Spades
**************
Deal again (y/n)? y
Number of jokers? 0
Number of hands? 10
Number of cards in a hand? 6
There will not be enough cards!
Number of jokers? 10
Number of hands? 3
Number of cards in a hand? 4
*** Hand 1 ***
Joker
King of Clubs
Five of Diamonds
Three of Spades
**************
*** Hand 2 ***
Ace of Hearts
Eight of Spades
Joker
Four of Spades
**************
*** Hand 3 ***
Four of Diamonds
Ten of Hearts
Six of Clubs
Joker
**************
Deal again (y/n)? n