Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- -----------Guess Game----------
- Author:Divyansh Chourey
- Source code:
- '''
- import random
- #Generating the random number
- randNum=random.randint(1,100)
- #print(randNum)
- print("$\tWelcome to Guess Game\t$")
- print("Guess any number from 1 to 100\n")
- #Opening the high_score file to print highscore
- with open ('high_score.txt','r') as f:
- highscore=f.read()
- highscore=int(highscore)
- # TODO: write code...
- print(f"The High Score is {highscore}\n")
- #Some of the parameters used
- active=True
- guess=0
- #While the user is active - continue
- while active:
- #Taking the input from user.
- user=int(input("Enter the number: "))
- #Algorithm to varify the results.
- if randNum == user:
- print("You guessed it right.\n")
- active=False
- else:
- if randNum>user:
- print("Wrong guess. Guess larger number.\n")
- elif randNum<user:
- print("Wrong guess. Guess smaller number.\n")
- guess+=1
- #Displaying the number of times user guessed
- print(f"You guess the number in {guess} guesses")
- if highscore==guess:
- print("You have just reached the record.")
- #Writing the score if it is higher than highscore
- elif (highscore>=guess):
- with open('high_score.txt', 'w') as f:
- guess=str(guess)
- f.write(guess)
- print("You broke the record.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement