Question
Problem One. Modify your program in Python from Problem Three of HW #7 (coding provided below) so that it records the guessing game in a
Problem One. Modify your program in Python from Problem Three of HW #7 (coding provided below) so that it records the guessing game in a file, as it plays the game. The file should end up looking something like this:
Game 1: The number is 8.
User guesses 5, too low.
User guesses 12, too high.
User guesses 10, too high.
User guesses 8, thats it!
Game 2: The number is 17.
User guesses 22, too high.
User guesses 8, too low.
User guesses 20, too high.
User guesses 13, too low.
User guesses 16, too low.
User guesses 17, thats it!
Game over!!!
Try to match this style.
previous coding:
import random def set_the_number(): """ Function that sets the number """ global _number _number = random.randint(1, maximum) def get_user_guess(): """ Function that reads the guess from user """ guess = int(input("Guess a number between 1 and " + str(maximum) + ": ")) return guess def guessing_game(): """ Function that plays a game """ # Assigning number set_the_number(); # Iterate till user guess correctly while True: # Reading guess guess = get_user_guess() # Comparing if guess < _number: print("Too low"); elif guess > _number: print("Too high"); else: print("You got it!"); break; def main(): """ Main function """ global maximum maximum = 20 # Loop till user want to quit while True: # Playing a game guessing_game() # Reading option opt = input(" Do you want to play another game(y/n)? "); # Checking input if opt.lower() != 'y': break; # Calling main function main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started