Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need help creating a function that will keep track of the lowest number of guesses since the user started the program . In

Hello, I need help creating a function that will keep track of the lowest number of guesses since the user started the program . In Python. Included below is my code so far.

import random

##Main Function def main(): number = random_num() name =get_name() game(name,number) ##Requests User's name and returns it def get_name(): name = input('Hello, what\'s your name?: ') return name

##Function creates and returns a random number def random_num(): number = 0 number = random.randint(1,100) return number

##Function takes the random number and creates a guessing game with it def game(name,number): cont = '' guessesTaken = 0 guesses = 999999 print('Good day to you,',name,' are you ready for a guessing game?!') ##Requests input if the user would like to continue cont = input('Would you like to play?(Type Yes or yes, No to exit) ')

##While loop for when the user wishes to continue while cont =='yes' or cont =='Yes': print('I\'m thinking of a number from 0-100') ##Requests user's guess and stores it guess = int(input('Pick your number: ')) while guess !=number:

##Too small if guess < number: print('Your guess is too low.') guessesTaken+= 1 guess = int(input('Pick your number: '))

##Too large elif guess > number: print('Your guess is too high.') guessesTaken+= 1 guess = int(input('Pick your number: '))

##Correct guesses that are even if guess == number and number%2==0: guessesTaken+= 1 print('Good job! You guessed my number in ' + str(guessesTaken) + ' guesses!', 'It is an even number') if guessesTaken

main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

=+Apply the three-step writing process to negative messages

Answered: 1 week ago

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

Did the team members feel that their work mattered

Answered: 1 week ago