Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def guess():
- num = randint(0,1000)
- tries = 0
- won, won_rew = False, False
- while True:
- try:
- usr_num = int(input("Guess the Number between 0 and 1000 : "))
- tries += 1
- if usr_num == num:
- if tries <= 5:
- won_rew = True
- break
- else:
- won = True
- break
- else:
- if usr_num < num:
- print("Actual Number is Larger...")
- else:
- print("Actual Number is Smaller...")
- except ValueError:
- print("You've Entered a WRONG Value...\n")
- if won_rew:
- print("You Won!!! It took you {} tries to guess the Actual Number...\nYou Get a Reward".format(tries))
- elif won:
- print("You Won!!! It took you {} tries to guess the Actual Number...".format(tries))
- def main():
- choice = 'y'
- while choice.lower() in ('y', 'n'):
- guess()
- choice = input("Do You want to Play Again (y/[n]) : ")
- if choice.lower() == 'y':
- continue
- elif choice.lower() == 'n':
- print("Thank You For Playing the Game...")
- break
- else:
- print("Invalid Choice...")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement