Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- guesses = 5
- guessed = False
- correct = randint(1,50)
- print("Welcome to vidya, you have 5 guesses to get the right number between or equal to 1 and 50")
- while(guesses > 0 and not guessed):
- badInput = True
- while(badInput):
- try:
- player = int(input("Guess: "))
- if(player > 0 and player < 51): badInput = False
- else: raise Exception
- except:
- print("Please make sure your guess is a whole number between or equal to 1 and 50")
- guesses -= 1
- if(player == correct):
- guessed = True
- break
- elif(player < correct):
- print("You guessed too low, %d attempts left" %guesses)
- else:
- print("You guessed too high, %d attempts left" %guesses)
- if(guessed):
- print("You guessed correct in %d attempts" %(5-guesses))
- else:
- print("The correct number was %d! You should try again" %correct)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement