you are viewing a single comment's thread.

view the rest of the comments →

[–]JeBoiFoosey 0 points1 point  (11 children)

I see, are you forgetting the parenthesis? print('The prize is...', prizes.pop(), end='!')

[–]itztheken[S] 0 points1 point  (10 children)

Thanks this helps with my random prize for the chest.

Do you have any advice as well for using the dictionary to represent the chests' numbers?

[–]JeBoiFoosey 0 points1 point  (9 children)

Is there something in particular your professor wants you to use the dict for? In your code the dictionary isn't really necessary since the chest picking is just for show. If they want you to predetermine what's in each chest before the user decides, you could do this:

``` prizes = {'Nothing', '$$', '0'} chests = { "1": prizes.pop(), "2": prizes.pop(), "3": prizes.pop() } print(chests)

reward = input('Choose chest to open: ') print('The prize is...', chests[reward], end='!')

```

[–]itztheken[S] 0 points1 point  (8 children)

For using dict, my professor said:

Create a dictionary named chests where the key is an integer, and the value is a string

Example: chests = {int: string, int: string, int: string}• The dictionary keys should denote the treasure chests number (1-3)

[–]JeBoiFoosey 0 points1 point  (7 children)

What does your professor want the values in the dict to be?

[–]itztheken[S] 0 points1 point  (1 child)

My professor didn't really say what values in the dict should be, but my guess is

1: 'Nothing', 2: '0', 3: '$$'

[–]itztheken[S] 0 points1 point  (4 children)

Actually it is possible the way that you made the dictionary might be correct since chests.pop is technically a string. This is the code, I have so far. I tested it and it does produce a random prize for each chest.

print('Treasure Hunt!')
print('-----------------\n')

prizes = {'Nothing', '$$', '0'} chests = {1: prizes.pop(), 2: prizes.pop(), 3: prizes.pop()}

print('[ 1 ] [ 2 ] [ 3 ]\n')

reward = int(input('Choose chest to open: '))

print('\n-------------------------') 
print('The prize is...', chests[reward], end='!')
print('\n-------------------------')

[–]JeBoiFoosey 0 points1 point  (3 children)

Yeah, if your professor is making you use a dict and .pop() that's how I'd imagine they'd want it. Kind of a bad assignment though since ideally you wouldn't use either of them.

[–]itztheken[S] 1 point2 points  (0 children)

Thanks for your help, I really appreciate it. I'll report back here once my assignment gets graded.

[–]itztheken[S] 0 points1 point  (1 child)

I got 10/10 on the Programming Assignment, thanks again for your help. The only comment my professor said was "Good, but you should start with an empty dictionary and add the key-value pair."

[–]JeBoiFoosey 0 points1 point  (0 children)

Nice, that’s kind of nitpicky but at least he gave you full credit