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
marishachu [46]
4 years ago
7

Create the logic for a game that simulates rolling two dice by generating two random numbers between 1 and 6 inclusive. The play

er chooses a number between 2 and 12 (the lowest and highest totals possible for two dice). The player then "rolls" two dice up to three times. If the number chosen by the user comes up, the user wins and the game ends. If the number does not come up within three rolls, the computer wins.
Computers and Technology
1 answer:
guajiro [1.7K]4 years ago
8 0

Answer:

The solution code is written in Python 3.

  1. import random  
  2. count = 0
  3. flag = False
  4. guess = int(input("Input your guess (2-12): "))
  5. while(count <=3):
  6.    dice1 = random.randint(1, 7)
  7.    dice2 = random.randint(1, 7)
  8.    if((dice1 + dice2) == guess):
  9.        flag = True
  10.    count += 1
  11.    
  12. if(flag):
  13.    print("User wins!")
  14. else:
  15.    print("Computer wins!")

Explanation:

A Random generator is needed for this question and therefore we start by importing Python random class (Line 1)

Next, create one counter variable,<em> count</em>, to ensure there will be only three rolling of the dices (Line 3).  We need another variable, <em>flag</em>, to track the status if the two dices equal to the <em>guess</em> number chosen by user (Line 4).

Next, prompt use to input a guess number (Line 5).

Within the while loop, we can use random class method <em>randint() to </em>generate random integer. The arguments 1 and 7 will give one random number ranged from 1 to 6 for <em>dice1</em> and<em> dice2</em>, respectively (Line 8 - 9).

If the total of<em> dice1 + dice2</em> equal to user <em>guess</em>, we turn the<em> flag </em>to <em>True</em>. If not, the <em>flag </em>will remain <em>False</em> after completing entire while loop.

If the <em>flag </em>turned to <em>True</em>, print the message "User Wins!" else print the message ("Computer wins!")

You might be interested in
What imbalance is fixed by a single right rotation?
slega [8]

Answer:

It balances a tree when a long path exist in the left subtree of the left of the root.

Explanation:

Rotation is an operation which is performed on the binary tree which changes the structure of the binary tree but it does not interfere with the order of elements.

A single right rotation strategy is basically for re balancing the tree.When there is along path which exists in the left subtree of the left of the root.

3 0
3 years ago
What are the uses of DVD Ram​
Verdich [7]

Answer:

Like ordinary random access memory (RAM), it can be repeatedly read, written to, and erased. Intended mostly for removable computer storage, DVD-RAM provides the capabilities of Rewriteable CD (CD-RW) - users can run programs from the discs, copy files to them and rewrite or delete them.

4 0
3 years ago
Read 2 more answers
A potential threat to administrators’ ability to manage the correctional system is
OlgaM077 [116]
(privatization) is your answer to this question you are asking 
4 0
3 years ago
Changing how information is represented so that it can be read by a person is called
Usimov [2.4K]

Answer:

Decode. To change how information is represented so that it can be read by a person.

Explanation:

Decoding is the ability to apply your knowledge of letter-sound relationships, including knowledge of letter patterns, to correctly pronounce written words. Understanding these relationships gives children the ability to recognize familiar words quickly and to figure out words they haven't seen before.

4 0
3 years ago
Which presentation feature would allow a business to include employees in other countries to participate in monthly status meeti
baherus [9]

Answer:

Explanation:

Broadcast slide show

7 0
3 years ago
Other questions:
  • The overall purpose of CSS is to modify the way web pages look without modifying the underlying HTML code. way tables render in
    12·2 answers
  • PLEASE HELP!!!!!!!!!!!
    11·2 answers
  • Which item is essential to know before sketching a navigation menu flowchart? template specifics, such as horizontal or vertical
    12·1 answer
  • Differences between Quality of Services and a Service of Quality approach
    9·1 answer
  • DRIVER ED
    13·2 answers
  • Name two different ways you can bring up the my computer folder
    9·2 answers
  • Which flowchart symbol is called the process symbol and contains the steps or actions in the process being depicted?
    6·2 answers
  • Draw the resistor’s voltage and current phasors at t=15ms. Draw the vectors with their tails at the origin. The orientation of y
    5·2 answers
  • Why do we create user accounts to customize our preferences​
    10·1 answer
  • Missing only a few days of school will not impact your grades.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!