2
Please Help
LukeBreeden1 (1)

Ok... I'm am trying to code a Yahtzee game with python and am having a bit of trouble. I'm new to python and heard that a dice game is a simpler task for beginners(guess I picked the wrong game). Anyway, what I'm having trouble with is that I'm trying to make a connection between the numbers rolled and the numbers the player chooses to keep. Can anyone help me... I can share if that is what's needed.

You are viewing a single comment. View All
Answered by Elizabeth11 (18) [earned 5 cycles]
View Answer
1
LukeBreeden1 (1)

I also need to keep the numbers that are chosen so that they won't get rerolled in the next roll.

3
Elizabeth11 (18)

@LukeBreeden1 You can create 2 lists. I'll call one roll_list and another player_choosen_list. You can change the names. Anyway, roll_list holds all of the intial numbers. Then print out these numbers and you can ask the player "do you want to keep a number?" then while the player says "yes" then have them input the number they want to keep. Add this number to the player_chosen_list Once the player answers the question "do you want to keep a number" with something other then yes then the boolean variable would be false and you could end the while loop. Then because you want to keep the numbers that are chosen so that they won't get rerolled take the initial list which is roll_list and loop through it and use a nested loop to check if there is a number that is inside of both the roll_list and the player_choosen_list. If so remove that number from the roll_list. Once the for-loops are done then reroll using the roll_list and you may have the reset the player_chosen_list.

1
LukeBreeden1 (1)

@Elizabeth11 Well that would work... but my lists are in different classes. Sorry, I didn't specify that.

1
Elizabeth11 (18)

@LukeBreeden1 Oh ok. Did you get everything to work now?