Write a python program:Let the user specify S (the number of sides on a die) and N(the number of tosses of two S -sided dice).Assume ((S << N) and (3 <= S <= 20)). Since each die side is labeled with a unique integer taken from the range[ 1,S ], the sum of each dice toss is in the range [ (2=1+1),(2*S=S+S) ]. For example, whenS = 6 , then the sum of each dice toss is in the range [ 2,12 ]. MakeN dice tosses and count how frequently each sum occurs. Output ahorizontal histogram that depicts the frequency distribution of the sums of theN dice tosses. Every sum in the range [ 2,2*S ] and its frequency of occurrence should be output using the formatXXX (XXXXXXXX) | ******whereXXXis the sum,(XXXXXXXX)is the frequency, and each'*'represents 1% of the 100% of frequencydistribution. The number of '*' output for each sum is computed by rounding the quotient (counts[sum]/N) up to the nearest integer. The entire histogram will contain (2*S-2+1) lines2 (XXXXXXXX) | ******3 (XXXXXXXX) | ******. . .. . .2*S (XXXXXXXX) | ******

Question
Asked Mar 2, 2020
1 views

Write a python program:

Let the user specify S (the number of sides on a die) and N
(the number of tosses of two S -sided dice).
Assume ((S << N) and (3 <= S <= 20)). Since each die side is labeled with a unique integer taken from the range
[ 1,S ], the sum of each dice toss is in the range [ (2=1+1),(2*S=S+S) ]
. For example, when
S = 6 , then the sum of each dice toss is in the range [ 2,12 ]. Make
N dice tosses and count how frequently each sum occurs. Output a
horizontal histogram that depicts the frequency distribution of the sums of the
N dice tosses. Every sum in the range [ 2,2*S ] and its frequency of occurrence should be output using the format
XXX (XXXXXXXX) | ******
where
XXX
is the sum,
(XXXXXXXX)
is the frequency, and each
'*'
represents 1% of the 100% of frequency
distribution. The number of '*' output for each sum is computed by rounding the quotient (counts[sum]/N) up to the nearest integer. The entire histogram will contain (2*S-2+1) lines
2 (XXXXXXXX) | ******
3 (XXXXXXXX) | ******
. . .
. . .
2*S (XXXXXXXX) | ******
check_circle

Expert Answer

star
star
star
star
star
1 Rating
Program Instructions:
  • Import the random library and prompt the user for the values of N and S.
  • Use a for loop for N times to generate random numbers between 2 to 2*S and store them in a list.
  • Use a for loop and dictionary to count the frequency of each number/sum.
  • Use a for loop and sorted() function to print the dictionary values in sorted manner.
  • Use round() function to round the quotient up to the nearest integer.
  • The value of sum is multiplied by 100 before diving it with N to increase the number otherwise the result of round() function will be 0.
Program:

# import random to generate random numbers

import random

# prompt user for S

S = int(input('Enter the value of S (the number of sides on a die): '))

# prompt user for N

N = int(input('Enter the value of N (the number of tosses of two S-sided dice): '))

dice_sum = []

# generate sums in range 2 to 2*S for N tosses

for i in range(N):

  dice_sum.append(random.randint(2,2*S))

freq = {}

# use a dictinory to calculate the count of each number

for items in dice_sum:

  freq[items] = dice_sum.count(it...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: In java Write a program that does the following:- reads an unspecified number of integers- determine...

A: Create an object for a Scanner class to take the inputs. Take a variable to insert the numbers. Take...

question_answer

Q: Write a program in java to calculate the area of circle.

A: Program Approach – Import the essential packages. Declare the class. Define the main method. Declar...

question_answer

Q: In JavaScript, what does "this" mean? How does it relate to a "global execution context"?

A: The global execution context is generated prior to any code that is executed. A new execution contex...

question_answer

Q: What is the output from the following print statement: print (1 / 3) print (10 + 3 * 7) print ((10 ...

A: We’ll answer the first three subparts of the question since the exact one wasn’t specified. Please s...

question_answer

Q: When is a constructor called? When an object is destroyed When it is called explicitly with the ...

A: Since there are multiple questions, the answer is provided only for few questions.

question_answer

Q: In C, Given an int variable k that has already been declared, use a do...while loop to print a singl...

A: //include the required header file #include &lt;stdio.h&gt;   //define main function int main() { //...

question_answer

Q: 2:31 ll LTE 4 3 - Chapter 8 lab 2.pdf CPS 229f 1 Chapter 8 – Lab 2 2020 Research and select an examp...

A: #include &lt;iostream&gt;#include &lt;iomanip&gt; // to access setw() using namespace std; int main(...

question_answer

Q: Convert the algorithm provided into C source code: Each year, the county property tax system calcula...

A: #include&lt;stdio.h&gt; //compute tax double calcTax(int value) { return value * 0.03; } int main()...

question_answer

Q: Please solve the below question using c++ asap asap and use basic logic

A: Create a struct Person with mentioned data and constructor. Create a function count that traverse th...