Last active
December 14, 2015 23:59
-
-
Save sa7dse/5170121 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
import random | |
import time | |
def secret_gen(): | |
random.seed() | |
while(1): | |
num = int(random.randint(1,100)) | |
yield num | |
def leave(secret): | |
timepassed = (int(time.time() - timestart)) | |
print("Aww you gave up. The secret number was %s" %(secret)) | |
print ("Game Over, it took %i seconds" % (timepassed)) | |
quit(0) | |
def main(): | |
secret = int(next(secret_gen())) | |
guess = 0 | |
i = 0 | |
global timestart | |
timestart = time.time() | |
print("Guess the secret number between 1 and 100. Press 0 to quit") | |
#print secret #Debugging only | |
while guess != secret: #a simpel loop to get the secret number | |
try: | |
try: | |
guess = int(raw_input("Guess:")) | |
except: | |
guess = int(input("Guess:")) | |
except ValueError: | |
print("Invalid input") | |
continue | |
if guess < 1: | |
leave(secret) #leaving the game are you? | |
if guess < secret: | |
print("To small") | |
if guess > secret: | |
print("To big") | |
i = i + 1 | |
if i > 10: | |
print("Noob you made it at %i tries" % (i)) | |
elif i == 1: | |
print("Lucky devil or Cheater? \n" "Never mind you made it by one try") | |
else: | |
print("Great, you made it at %i tries!" % (i)) | |
timepassed = (int(time.time() - timestart)) | |
print("Game Over, it took %i seconds" % (timepassed)) | |
if __name__=="__main__": | |
while(1): | |
main() | |
print("\n\n Keep on rolling...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment