Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. from random import randint
  2. guesses = 5
  3. guessed = False
  4. correct = randint(1,50)
  5. print("Welcome to vidya, you have 5 guesses to get the right number between or equal to 1 and 50")
  6.  
  7. while(guesses > 0 and not guessed):
  8.     badInput = True
  9.     while(badInput):
  10.         try:
  11.             player = int(input("Guess: "))
  12.             if(player > 0 and player < 51): badInput = False
  13.             else: raise Exception
  14.         except:
  15.             print("Please make sure your guess is a whole number between or equal to 1 and 50")
  16.     guesses -= 1
  17.     if(player == correct):
  18.         guessed = True
  19.         break
  20.     elif(player < correct):
  21.         print("You guessed too low, %d attempts left" %guesses)
  22.     else:
  23.         print("You guessed too high, %d attempts left" %guesses)
  24. if(guessed):
  25.     print("You guessed correct in %d attempts" %(5-guesses))
  26. else:
  27.     print("The correct number was %d! You should try again" %correct)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement