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
Jobisdone [24]
4 years ago
15

Create a program that will play the “cows and bulls” game with the user. The game works like this: Randomly generate a 4-digit n

umber. Ask the user to guess a 4-digit number. For every digit that the user guessed correctly in the correct place, they have a “cow”. For every digit the user guessed correctly in the wrong place is a “bull.” Every time the user makes a guess, tell them how many “cows” and “bulls” they have. Once the user guesses the correct number, the game is over. Keep track of the number of guesses the user makes throughout the game and tell the user at the end. Say the number generated by the computer is 1038.
Computers and Technology
1 answer:
riadik2000 [5.3K]4 years ago
7 0

Answer:

Welcome to the Cows and Bulls Game!

 Enter a number:

 >>> 1234

 2 cows, 0 bulls

 >>> 1256

 1 cow, 1 bull

 ...

"""

import random

def compare_numbers(number, user_guess):

   cowbull = [0,0] #cows, then bulls

   for i in range(len(number)):

       if number[i] == user_guess[i]:

           cowbull[1]+=1

       else:

           cowbull[0]+=1

   return cowbull

if __name__=="__main__":

   playing = True #gotta play the game

   number = str(random.randint(0,9999)) #random 4 digit number

   guesses = 0

   print("Let's play a game of Cowbull!") #explanation

   print("I will generate a number, and you have to guess the numbers one digit at a time.")

   print("For every number in the wrong place, you get a cow. For every one in the right place, you get a bull.")

   print("The game ends when you get 4 bulls!")

   print("Type exit at any prompt to exit.")

   while playing:

       user_guess = input("Give me your best guess!")

       if user_guess == "exit":

           break

       cowbullcount = compare_numbers(number,user_guess)

       guesses+=1

       print("You have "+ str(cowbullcount[0]) + " cows, and " + str(cowbullcount[1]) + " bulls.")

       if cowbullcount[1]==4:

           playing = False

           print("You win the game after " + str(guesses) + "! The number was "+str(number))

           break #redundant exit

       else:

           print("Your guess isn't quite right, try again.")

Explanation:

You might be interested in
This OS was created by a developer named Torvalds.
GREYUIT [131]
The answer to this problem is Linux
7 0
3 years ago
Which best describes a VPN?
aleksandr82 [10.1K]

A private connection through a private network

8 0
3 years ago
Read 2 more answers
If the value of the expression,
mr Goodwill [35]

Answer:

<u>Arithmetic underflow</u>

Explanation:

Great question, it is always good to ask away and get rid of any doubts that you may be having.

Since the answer given is a negative. We can say the error that is seen here is an <u>Arithmetic underflow </u>error. This is because the answer given is a smaller absolute value which the computer cannot actually represent or save in its memory in the CPU. Therefore this is the closest representation of the arithmetic error displayed.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

8 0
3 years ago
Would anyone be willing to give me free a psn card
maks197457 [2]

Answer:

No??

Explanation:

why would i do that?

6 0
4 years ago
Omg plz help its a late assignment
balu736 [363]

Answer:

C it's the correct option for your answer!!

6 0
3 years ago
Other questions:
  • In Paint, which of the following are ways to use a picture that you have saved on your computer? (Select all that apply.)
    8·1 answer
  • Applying what formatting option to your excel workbook will make it easier to read when printed out?
    13·1 answer
  • To keep a desktop computer or a server powered up when the electricity goes off in addition to protection against power fluctuat
    8·2 answers
  • If you think the user might enter 24.9, you should create a float variable. true or false
    9·1 answer
  • What are two example of ways an electronic record may be distributed to others?
    11·1 answer
  • What is the meaning of the phrase the video has gone viral
    9·2 answers
  • Cleo is new to object oriented programming. which type of action can be taken on on object?
    14·2 answers
  • HEYY GUYS START REPORTING ALL THE SPAMMERS PLSS!!!!! For the spammers, I hope you go to hell &gt;:c!!!!!!!!!!!
    14·1 answer
  • The primary source of help for technical problems with BC Online (computer settings, password, etc.) is:
    14·1 answer
  • A packet switch has 5 users, each offering packets at a rate of 10 packets per second. The average length of the packets is 1,02
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!