Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3: Add the following two functions to this Python Yatzee program: 1) Add functions to calculate points for rolling twos (2 points for every

Python 3:

Add the following two functions to this Python Yatzee program:

1) Add functions to calculate points for rolling twos (2 points for every 2 rolled), threes (3 points per 3), fours (4 points per 4), fives (5 points per 5) and sixes (6 points per 6) 2) Add a function to calculate another dice combination (for example: small straight, large straight, three of a kind, four of a kind).

from random import randint def rollDice(lst): for count in range(5): lst.append(randint(1,6)) def displayRolls(lst): for die in lst: print(die, " ",end="") print() print("_" * 17) print() def yahtzee(lst): numToCompare = lst[0] matching = True index = 1 while matching and index < 5: if lst[index] != numToCompare: matching = False index += 1 if matching: return 50 else: return 0 def ones(lst): total = 0 for die in lst: if die == 1: total += 1 return total def fullhouse(lst): copy = list(lst) copy.sort() if copy[0] == copy[1] and copy[2] == copy[3] and copy[3] == copy[4]: return 25 elif copy[0] == copy[1] and copy[1] == copy[2] and copy[3] == copy[4]: return 25 else: return 0 def main(): dicelst = [] rollDice(dicelst) displayRolls(dicelst) points = yahtzee(dicelst) print("%-12s" %"Yahtzee:", "%3d" % points) points = ones(dicelst) print("%-12s" %"1's: ", "%3d" %points) points = fullhouse(dicelst) print("%-12s" %"Full house: ", "%3d" %points) main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions