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
Hi there. I need to know that if I take computer fundamentals, will that class teach anything about graphic design or digital de
Vedmedyk [2.9K]
Hi there!

I have taken a computer fundamentals class before and they did skim over the topic, but they did not go into depth on it at all. If you really want to learn about that stuff I suggest you find a course that is specifically on that topic or something that is closer related then a general <span>computer fundamentals course.

-Your friend in tech,
</span>ASIAX <span>  </span><span>Frequent Answerer</span>
8 0
3 years ago
What can be designed to create annoying glitches or destroy data
Katen [24]

I guess the best answer is Virus.

Virus is a malicious computer program that is designed to create annoying glitches or destroy data.

3 0
3 years ago
Read 2 more answers
Characteristics of successful entrepreneurs include
crimeas [40]
The answer would be A because grit means to fight hard to get what you want. Submission would be to give in to pressure and give up. Self-importance would be to only focus on yourself and no one else. A short attention span would not work out for you because you get distracted easily.
8 0
3 years ago
Which type of movement lets the player control an object's movement?
Levart [38]
X and y imposed axis
7 0
3 years ago
Write a function that accepts an int array and the array’s size as arguments. 1. The function should create a new array that is
Contact [7]

Answer:

The question seems to be incomplete. Analyzing the full question the answer has been explained below. Please let me know if your answer requirement was other than this.

Explanation:

#include<iostream>

#include<fstream>

using namespace std;

int *extend(int arr[], int N)

{

  // create a new array that is twice

  //the size of the argument array.

  int *new_arr = new int[2 * N];

  int i;

  // copy the contents of the argument

  //array to the new array

  for (i = 0; i < N; i++)

      new_arr[i] = arr[i];

  // initialize the unused elements

  //of the second array with 0

  for (i = N; i < 2 * N; i++)

      new_arr[i] = 0;

  // return a pointer to the new array

  return new_arr;

}

//main function

int main()

{

  // Declare the array

  int N;

  //Prompt and reads an integer N

  cout << "Enter N : ";

  cin >> N;

  // If the integer read in from

  //standard input exceeds 50 or is less than 0

  if (N < 0 || N > 50)

      // The program terminates silently

      exit(0);

  // open file in read mode

  ifstream in("data.txt");

  // create an array of size N

  int *arr = new int[N];

  int i;

  // reads N integers from a file

  //named data into an array

  for (i = 0; i < N; i++)

  {

      // read integer from file

      in >> arr[i];

  }

  //then passes the array to your

  //array expander function

  int *new_arr = extend(arr, N);

  // print the extended array

  for (i = 0; i < 2 * N; i++)

      cout << new_arr[i] << endl;

  in.close();

  return 0;

}

4 0
3 years ago
Other questions:
  • How old do you have to be to get paid to wave at liberty tax in Abilene tx
    8·2 answers
  • What type of electronic monitoring involves an offender being contacted periodically by telephone or beeper to verify his or her
    5·1 answer
  • What is the purpose of a Program Epic?
    7·2 answers
  • You use worksheets to perform calculations. How do you perform these calculations? ______ are used for performing calculations i
    12·2 answers
  • One of the Employee responsibilities to LOTO is:
    5·1 answer
  • A successful web-based strategy that helps a business spread the word about its website and products is called:
    15·1 answer
  • What are the tyoe of typical application of mainframe computer<br>​
    6·1 answer
  • Write a program that reads a list of integers, and outputs those integers in reverse. The input begins with an integer indicatin
    6·1 answer
  • What are the steps involed in accepting all the changes in a document?
    8·1 answer
  • A. Fill in the blanks:
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!