Skip to content
Snippets Groups Projects
Commit 30a03528 authored by cprutean's avatar cprutean
Browse files

Upload New File

parent 4aad9d2f
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:a21a577a tags:
# Hello
%% Cell type:code id:cf5ba095 tags:
``` python
"""
Simple guess game that will loop until you get it right.
Be very careful that you follow the indentation here.
"""
import random
def main():
correct = random.randint(1,9) # the randon correct value
print("Guess the number between 1 and 9")
number_of_tries = 0
while True: # Start of infinite loop
guess = int(input("Have a guess (give an int) : "))
number_of_tries += 1
if guess == correct: # Test if the guess is correct
print("You guessed right")
break # If correct break the loop
else:
print("You guessed wrong.... have another go")
# End of loop
# This is after loop.
print("You took " + str(number_of_tries) + " attempt to guess right")
main()
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment