vendredi 27 février 2015

How would I append items to a list, use that information, clear the list, and then use it again?

This is just a part of the code that I am using to try to make a game sort of like yahtzee. It probably looks a little rough (this is my first project since finishing the codeacademy course).


What I need to do is put the number between 1-6 randomly chosen associated with each dice into a list that I can work with to eventually decide if the numbers are 3 of a kind, four of a kind and so on.


I just need a simple way to work with the numbers in the list and then after they choose to roll again I can erase the numbers and add new random numbers to the list.



dice_1 = random.randrange(1,7)
dice_2 = random.randrange(1,7)
dice_3 = random.randrange(1,7)
dice_4 = random.randrange(1,7)
dice_5 = random.randrange(1,7)

dice_list = []

def roll_dice(): #adds random number of dice to dice_list
dice_list.append(dice_1)
dice_list.append(dice_2)
dice_list.append(dice_3)
dice_list.append(dice_4)
dice_list.append(dice_5)

def choice():
player_turn = 1
while player_turn <= 3:
roll_again = raw_input("Would you like to roll again? (yes or no)")
if len(roll_again) == 3:
del dice_list[0:len(dice_list)]
roll_dice() #Find out how to delete what was already in that list and exchange it with the new numbers
dice_pics()
break
player_turn += 1
elif len(roll_again) == 2:
read_dice()
break
else:
print "That was not a yes or no answer! Try again!"


`





Aucun commentaire:

Enregistrer un commentaire