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
A(n) _____ is any hardware component that allows you to enter data and instructions into a computer or mobile device.
Darya [45]
Hello there.

<span>A(n) _____ is any hardware component that allows you to enter data and instructions into a computer or mobile device.

</span><span>Input Device</span>
4 0
3 years ago
​in a data dictionary, a(n) _____ is the smallest piece of data that has meaning within an information system.
Ksivusya [100]

In a data directory, a 01 is the smallest piece of data that has meaning within an information systems.

4 0
4 years ago
What is similar software engineering, Hardware engineer, Network Architect, and Web developer?
Oliga [24]

I Am Pretty Sure The Answer Is - "B"

Hope This Help's

5 0
3 years ago
Switches: Select one:
const2013 [10]

Answer:

b. connect two or more network segments that use different data link protocols

Explanation:

A switch is an analog device that allows to interconnect networks, it is possibly one of the devices with a higher level of scalability. It is important to clarify that a Switch does not only provide connectivity with other networks, nor does it provide connectivity with the Internet, for this purpose a router is necessary.  

6 0
4 years ago
What is the purpose of anti-bullying laws
nasty-shy [4]
The purpose of anti-bullying laws is so that people aren’t getting bullied because when someone gets bullied it could cause them to become depressed and not happy on who they are
6 0
3 years ago
Read 2 more answers
Other questions:
  • Excel contains ____ tools not available in access.
    12·1 answer
  • Jill is interested in a career as a paramedic. She is trained to use medical equipment, she remains calm under pressure, and she
    15·1 answer
  • Which of the following statements are valid in Java? (Assume that console is Scanner object initialized to the standard input de
    15·1 answer
  • The loop body instructions in the _____ statement always are processed at least once.
    6·1 answer
  • Given a long integer representing a 10-digit phone number, output the area code, prefix, and line number using the format (800)
    11·1 answer
  • What is syntax?
    15·1 answer
  • Tower of Hanoi algorithm 4 disks
    12·2 answers
  • The study and practice of information storage and retrieval is called
    11·1 answer
  • Very few games have any sort of narrative, not even a simple one that involves setting the mood through color, sound, environmen
    12·1 answer
  • How to connect two monitors for one desktop
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!