Created
June 26, 2021 16:33
-
-
Save Just-Simple-59/b8c056b136f0ffd9c072ca7df7dd0fa7 to your computer and use it in GitHub Desktop.
Generate a random number between 1 and 9 (including 1 and 9). Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly right. Keep track of how many guesses the user has taken, and when the game ends, print this out.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
a = random.randint(1, 9) | |
i = 0 | |
def main(): | |
b = int(input("Guess the number\n")) | |
global i | |
if a < b: | |
print("You have guessed a number higher to that of original number\n") | |
i = i + 1 | |
main() | |
if a > b: | |
print("You have guessed a number lower to that of original number\n") | |
i = i + 1 | |
main() | |
if a == b: | |
print("Congratulations you have guessed the number correctly\n") | |
print("You have taken " + str(i) + " chances to guess the right number") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment