'How do you retrieve set values without removing the values, and randomly inputting them into a dictionary?
It's a lot. However, we are trying to make a code in which the user picks from three options, where each one has different prizes. We have to use a set = '', '', '' (strings) and the dictionary = {1: value, 2: value, 3: value}. WE have to randomize the set strings to the values in the dictionary every time so the user can continuously get a different prize regardless of the number they choose.
Since they are sets, we can't index them. Using basic coding from python or a method, what is a good way to retrieve, and randomize these strings to a different dictionary value?
print("[ 1 ] [ 2 ] [ 3 ] \n")
Prizes = set("Oculus X", "N/A", "Money")
gift_box = {1: Prizes, 2: Prizes, 3: Prizes}
# Will let user choose
user_input = int(input("> Choose a Gift Box to open: "))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
