MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / guess

Function guess

projects/Guess Number/guess_number.py:37–54  ·  view source on GitHub ↗
(num, user_guess, num_of_guesses)

Source from the content-addressed store, hash-verified

35
36# function to handle checking user input against random number and upper/lower bounds
37def guess(num, user_guess, num_of_guesses):
38 upper_limit = 10
39 lower_limit = 1
40 while num != user_guess:
41 if num > user_guess:
42 print(f"\nNumber is higher than {user_guess}")
43 lower_limit = user_guess
44 user_guess = enter_and_verification(lower_limit + 1, upper_limit)
45 num_of_guesses = num_of_guesses + 1
46 elif num < user_guess:
47 print(f"\nNumber is lower than {user_guess}")
48 upper_limit = user_guess
49 user_guess = enter_and_verification(lower_limit, upper_limit - 1)
50 num_of_guesses = num_of_guesses + 1
51 else:
52 print()
53 print(f"\nCongrats! You've guessed the correct number! It was {num}.\n")
54 print(f"\nYou have tried {num_of_guesses+1} times to find the number.\n")
55
56
57# while loop to prompt user to play intially, then continue to play or not

Callers 1

guess_number.pyFile · 0.70

Calls 1

enter_and_verificationFunction · 0.85

Tested by

no test coverage detected