Question: Please use Python to solve this problem. I've solved the first question already. However, I got stuck in the second one. I couldn't make python

 Please use Python to solve this problem. I've solved the firstquestion already. However, I got stuck in the second one. I couldn't

Please use Python to solve this problem.

I've solved the first question already. However, I got stuck in the second one.

I couldn't make python to exclude the result (7) in the Minimum dice sum and the Maximum dice sum.

And sometimes the outputs of minimum and maximum are not the minimum number and maximum number added in the list.

here is my code:

import random

#1

def roll_dice(n): '''returns the result of rolling n fair dice in a list.''' List=[] for i in range(n): rolls = random.randint(1,6) List.append(rolls) return List

#2

def dice_game(): '''uses the function from Q1 as a helper function, to repeatedly roll a pair of dice until the sum of the dice is 7.''' List=[] score=0 average=0 roll = roll_dice(2) while sum(roll) != 7: score=score+sum(roll) average=average+1 List.append(roll) roll = roll_dice(2) List.append(roll) print("Game Score:",score) print("Dice pairs rolls:",List) print("Minimum dice sum:",sum(min(List))) print("Maximum dice sum:",sum(max(List))) print("Average dice sum:",score/average)

this is my output:

Game Score: 19 Dice pairs rolls: [[3, 5], [1, 5], [4, 1], [2, 5]] Minimum dice sum: 6 Maximum dice sum: 5 Average dice sum: 6.333333333333333

the minimum dice sum should be 5

and the maximum dice sum should be 8

The random module can generate random numbers. One application is rolling a fair dice, which will produce a 1,2,3,4,5 or 6. The code below should explain how to generate random ints: >>import random >>for i in range(20) n random.randint(1,6) print(n,end-') 4413 13253 14545 613324 (1) [10 pts] Write a function, roll_dice(n), which returns the result of rolling n fair dice in a list. n is an int and is >=1. Sample run (your results will almost certainly be different from mine-after all, we are simulating dice rolls) for n in range(1,7);: import ran oorm print(roli_dice(n)) roll-dice(N): retuns the result of olina, n farr dice in a list def [6, 5) 12, 3, 6) List -C for i in range (n) List.arpendC rolls) retum LiS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!