1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
andrezito [222]
3 years ago
12

Create a function that should simulate a game involving the rolling of a standard six-sided dice between two players. The functi

on takes in the integer number of rounds, which corresponds to how many games to play. Each game consists of both players rolling the dice five times each, whichever player has the highest average die roll from their five rolls wins the round.
Computers and Technology
1 answer:
Law Incorporation [45]3 years ago
4 0

Answer:

import random

def roll_dice(r):

   score1 = 0

   score2 = 0

   for i in range(r):

       for j in range(5):

           score1 += random.randint(1,6)

           score2 += random.randint(1,6)

           

       avg1 = score1/5

       avg2 = score2/5

       

       if avg1 > avg2:

           print("Player1 won the " + str(i+1) + ". round ")

       elif avg1 < avg2:

           print("Player2 won the " + str(i+1) + ". round ")

       else:

           print("Tie")

       

       score1 = 0

       score2 = 0

           

roll_dice(3)

Explanation:

Import the random module

Create a function called roll_dice that takes one parameter r

Initialize two scores as 0 for the players

Create a nested for loop. The outer loop will simulate the rounds and inner loop will simulate the each roll.

Inside the inner loop which iterates five times, generate random numbers for two players and add these numbers to their score.

When the inner loop is done, calculate the average score of the players. If the first average is greater, player1 wins the round. If the second average is greater, player2 wins the round. Otherwise, it is a tie. Also, set the scores to zero so that they start again.

Call the function with parameter 3, simulating 3 rounds

You might be interested in
How do you change a automatic transmission
irinina [24]

Answer:

ohhh ok to all transactions.

6 0
3 years ago
When you use the Query Editor to run a query that returns an xml type, theManagement Studio displays the XML data in blue with u
Ad libitum [116K]
Answer is c hope this helps
6 0
3 years ago
Websites using www showed up on the internet for the first time in -992
pogonyaev
1991 was the year websites first started to use www. (world wide web)
8 0
3 years ago
Amy, a project manager, needs to make a plan that ensures consistent delivery of the right message to the right people at the ri
AleksAgata [21]
I would have to say the answer is D.) A communication plan. Hope this helps! :-)
7 0
3 years ago
How will I go about conducting the investigation on fake news
Leno4ka [110]

Answer:

You can begin your report, and write about CNN, BBC, or any other liberal news network.

Explanation:

5 0
3 years ago
Other questions:
  • (Financial application: compound value) Suppose you save $100 each month into savings account with an annual interest rate of 5%
    6·1 answer
  • Is 37 words per minute when typing an okay grade?
    15·2 answers
  • These statements describe the NOS.(choose all that applies)
    13·2 answers
  • ZigBee is an 802.15.4 specification intended to be simpler to implement, and to operate at lower data rates over unlicensed freq
    7·1 answer
  • Which of the following describes cloud computing?​
    10·1 answer
  • The design of a blog refers to:
    8·1 answer
  • a certain kind of fish in the ocean eats only algae. a seal eats this fish a bear eats the seal .when the bear dies,it’s recycle
    6·1 answer
  • Why is E in DELL tilted?​
    5·2 answers
  • Anybody want to help me figure out how to put this on a resumè
    12·1 answer
  • What initialization vector (IV) do most weak implementations of the Wireless Equivalency Protocol (WEP) use
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!