Write an application in Python that allows a user to play the game Bulls and Cows against a computer. The game works as follows: The computer chooses a 4-digit number in secret. The digits must all be different.  The user then guesses the number and the computer will provide the number of matching digits. If the matching digit is in the right position it is a "bull", if it is in a different position it is a "cow". If the user guesses a number with repeat digits that is partially correct the rule is that a correct digit can only count once and bulls count before cows. Your program should report the number of attempts the user needed to guess the number and it should let a user play as many times as they wish in a single session. Hint: you may find it easier to store these numbers as strings or in lists rather than as plain integers. You must use the attached templates.  Write the code that is needed to complete the three functions in the bulls_and_cows module and the play_game function in the game module. The play_game function should make use of the functions you write in the bulls_and_cows module. Do not modify the main function in the game module. Your code must work with the main function that is provided as is. Template for cows_and_bulls.py: import random def generate_secret(): ''' Generates a 4 digit number with no repeat digits'' It converts the number to a string and returns it''' #add your code here return secret def how_many_bulls(answer,guess): ''' Returns the number of bulls the guess earns when the secret number is answer. Both answer and guess should be strings''' #add your code here return bulls def how_many_cows(answer, guess): ''' Returns the number of bulls the guess earns when the secret number is answer. Both answer and guess should be strings''' #add your code here return cows Template for game.py: import bulls_and_cows as bc def main(): # Do not change this function! print('Welcome to Bulls and Cows death match!') again='y' while (again=='y'): play_game() again=input('would you like to play again? (y/n)') print('So long sucker!') def play_game(): ''' Plays one interactive game of bulls and cows on the console''' #add your code here #call the main function to run the game main()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write an application in Python that allows a user to play the game Bulls and Cows against a computer. The game works as follows: The computer chooses a 4-digit number in secret. The digits must all be different.  The user then guesses the number and the computer will provide the number of matching digits. If the matching digit is in the right position it is a "bull", if it is in a different position it is a "cow".

If the user guesses a number with repeat digits that is partially correct the rule is that a correct digit can only count once and bulls count before cows.

Your program should report the number of attempts the user needed to guess the number and it should let a user play as many times as they wish in a single session. Hint: you may find it easier to store these numbers as strings or in lists rather than as plain integers.

You must use the attached templates.  Write the code that is needed to complete the three functions in the bulls_and_cows module and the play_game function in the game module. The play_game function should make use of the functions you write in the bulls_and_cows module. Do not modify the main function in the game module. Your code must work with the main function that is provided as is.

Template for cows_and_bulls.py:

import random

def generate_secret():

''' Generates a 4 digit number with no repeat digits''

It converts the number to a string and returns it'''

#add your code here

return secret

def how_many_bulls(answer,guess):

''' Returns the number of bulls the guess earns when the

secret number is answer. Both answer and guess should be strings'''

#add your code here

return bulls

def how_many_cows(answer, guess):

''' Returns the number of bulls the guess earns when the

secret number is answer. Both answer and guess should be strings'''

#add your code here

return cows

Template for game.py:

import bulls_and_cows as bc

def main():

# Do not change this function!

print('Welcome to Bulls and Cows death match!')

again='y'

while (again=='y'):

play_game()

again=input('would you like to play again? (y/n)')

print('So long sucker!')

def play_game():

''' Plays one interactive game of bulls and cows on the console'''

#add your code here

#call the main function to run the game

main()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education