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
When proofreading, you should ____.
victus00 [196]
Take the time to carefully look over your work
4 0
4 years ago
Read 2 more answers
Help I will mark brain list I promise!!
Valentin [98]

Answer:

we need more explanation

6 0
3 years ago
In social networking websites such as twitter, people leave narrow minded and subjective remarks and upload unacceptable videos.
koban [17]
The advice is That you Message Them To remind Them Those Type of posts are not appropriate if people on social Media say bad Things To you you block Them if people don’t Treat you nice
8 0
3 years ago
What is the purpose of the "time-to-live" (TTL) field of the IPv4 packet? a. ensures that the packet remains in the network long
Arisa [49]

Answer:

c. it prevents the packet from remaining indefinitely in the network thus helping to prevent network congestion

Explanation:

It prevents the packet from remaining indefinitely in the network thus helping to prevent network congestion

TTL is a value which is shown so that we can estimate that the packet that will tell the network router whether the packet has been in the network for enough time so that it should be discarded from the network or not.

6 0
3 years ago
A software program installed without the user's knowledge and designed to alter the way a computer operates or to cause harm to
RSB [31]

Answer:

The correct answer for the given question is "Computer virus"

Explanation:

A computer virus is a software program that is installed automatically without user's knowledge and designed to duplicate itself .The main purpose of computer virus is to harm the computer system.

Some of the points regarding computer virus

1.The computer virus contain malicious software Which harm the computer system.

2.It damage the  computer computer system in such away that sometimes users will unable to access some certain functionality of computer system.

5 0
3 years ago
Other questions:
  • Points Possible: 6, Points Correct: 4
    6·1 answer
  • A coworker is concerned about the veracity of a claim because the sender of an email denies sending it. The coworker wants a way
    6·1 answer
  • In the web address www.microsoft, the "" is the _____ meaning _____. A. B. C. D. Group of answer choices top-level domain (TLD);
    6·1 answer
  • federal law requires public libraries to install filtering software on computers to prevent children from accessing adult conten
    14·1 answer
  • What can you use on Code.org's Web Lab to find and fix problems when you are writing code for your website?
    13·1 answer
  • How do i code........​
    6·2 answers
  • Which of the following shows the assignment of a string to a variable? Select 3 options.
    11·2 answers
  • Jason is playing a game in which players must maneuver around changing barriers
    10·1 answer
  • In which directory would a system administrator store scripts that should be run monthly by the cron daemon?
    10·1 answer
  • A time management tool in a help desk software package probably has the greatest impact on the productivity of _____.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!