Write a Python 35 program using IDLE that plays a modified Y

Write a Python 3.5 program using IDLE that plays a modified Yahtzee game. You will allow a single player to play with 5 dice. For those of you who know how to play the game, you will only play the top half of the game. You will allow the user to have exactly 6 turns. On each turn the player rolls all 5 dice. For the basic game, you will roll for ones on the first turn, twos on the second turn, and so on until you roll for sixes on the last turn. In a single turn you get 3 tries. Each try you may roll all of the dice, some of the dice, or none of the dice. When you have rolled on try one of turn one, you will \"keep\" the ones that you rolled, and will try for more ones on the next two rolls. The total number of ones rolled on the first turn will be added to your overall score. Then you will start with turn two when you count the total number of twos rolled in all of 3 tries. When you have completed your six turns, a final score is printed out with a congratulatory message.

Solution

/* python program displaying playing of a yahtzee game*/

import random
main()
def ofkind(dice):
ofakind = 1
for x in range(5):
current = x
count = 1
while count != -1:
if current + 1 < 5:
if dice[current + 1] == dice[x]:
current = current + 1
count = count + 1
if count > ofakind:
ofakind = count
else:
count = -1
else:
count = -1

if ofakind == 5:
print(\"Five of a Kind: 50 points.\")
return 50
  
elif ofakind == 4 or ofakind == 3:
total = 0
for index in range(5):
total = total + int(dice[index])
if ofakind == 4:
total = total + 10
print(\"Four of a Kind: \" + str(total) + \" points.\")
return total
else:
no_duplicates = []
for index in range(5):
if dice[index] not in no_duplicates:
no_duplicates.append(dice[index])
if len(no_duplicates) == 2:
print(\"Full House: 25 points.\")
return 25
else:
total = total + 5
print(\"Three of a Kind: \" + str(total) + \" points.\")
return total
else:
return 0

def straight(dice):
straight = 1
for index in range(len(dice)):
current = index
count = 1
while(current != -1):
if current + 1 < len(dice):
if int(dice[current + 1]) - int(dice[current]) == 1:
current = current + 1
count = count + 1
elif int(dice[current + 1]) == int(dice[current]):
current = current + 1
else:
current = -1
else:
current = -1
if count > straight:
straight = count
if straight == 4:
print(\"Small Straight: 30 points.\")
return 30
elif straight ==5:
print(\"Large Straight: 40 points.\")
return 40
else:
return 0

def patterns(dice):
score = of_kind(dice)
if score == 0:
score = straight(dice)
if score == 0:
print(\"No Pattern: 0 points.\")
return score

  
def main():
totalscore = 0
for x in range(1,6):
print(\"Turn \" + str(x) + \"!\")
dice = []
for x in range(5):
dice.append(random.randint(1,6))
print(\"Roll 1: \", end =\"\")
for x in range(len(dice)):
if x < len(dice) - 1:
print(dice[x], end =\" \")
else:
print(dice[x])
keep = input(\"Which numbers would you like to keep? \")
keep = keep.split(\',\')
print(\"Roll 2: \", end =\"\")
for x in range(5):
if str(x + 1) not in keep:
dice[x] = random.randint(1,6)
if x < len(dice) - 1:
print(dice[x], end =\" \")
else:
print(dice[x])
dice.sort()
score = patterns(dice)
totalscore = totalscore + score
print(\"Final score: \" + str(totalscore) + \" points.\")

Write a Python 3.5 program using IDLE that plays a modified Yahtzee game. You will allow a single player to play with 5 dice. For those of you who know how to p
Write a Python 3.5 program using IDLE that plays a modified Yahtzee game. You will allow a single player to play with 5 dice. For those of you who know how to p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site