Here is a code you can use instead:
#Random number and date/time is imported
import random
from datetime import datetime
currenttime = str(datetime.now())
currenttime = (
currenttime[0:19]) #Ensures that only the first 19 digits of the date and time is displayed
YES_LIST =("yes", "sure", "yeah", "ye", "yea", "y", "fine", "okay", "ok", "yep")
score = 0 #To add a point system score must equal to 0 at the start of the game
GuessesTaken2 = 0 #GuessesTaken2 calculates the total guesses out of all the games played by player so this information can be exported into the text file
Name = input("What is your name? ") #game asks for player's name
print("Hello {}, Let's play a number guessing game. I am thinking of a number between 1 and 100.".format(Name))
#game begins
def main():
hidden = random.randint(1,100) #random number between 1 and 100 is generated
GuessesTaken = 0 # used to calcualte the guesses taken each game
while GuessesTaken < 6: #loop that automatically breaks after 6 guesses
guess = int(input("Guess which number I am thinking of: "))
GuessesTaken = GuessesTaken + 1;
global GuessesTaken2 #assigning GuessesTaken2 as a global function will allow the game to use it outside the loop
GuessesTaken2 = GuessesTaken2 + 1;
GuessesLeft = 6 - GuessesTaken; #algorithm to figure out how many guesses are left
if guess > hidden and GuessesLeft==0: #when there are no guesses left and the guessed number is higher than the actual number, the loop is automatically broken
print("Your guess is too high, you are unfortunately out of guesses!")
print("The number I was thinking of was actually {}".format(hidden))
restart()
if guess > hidden and GuessesLeft > 0: #If the guess is too high but there are still guesses left, the game allows you to guess again
print("Your guess is too high, you have {} guess/es left".format(GuessesLeft))
if guess < hidden and GuessesLeft==0: #when there are no guesses left and the guessed number is lower than the actual number, the loop is automatically broken
print("Your guess is too low and you are unfortunately out of guesses!")
print("The number I was thinking of was actually {}".format(hidden))
restart()
if guess < hidden and GuessesLeft > 0: #If the guess is too low but there are still guesses left, the game allows you to guess again
print("Your guess is too low, you have {} guess/es left".format(GuessesLeft))
if guess==hidden: #When the number is guessed correctly, the player gains points
global score #assigining score as a global function will allow the game to use it outside the loop
score = score + 5 #score increases by 5 each time you guess the number correctly
print("Hit!")
print("Congratulations {} !".format(Name))
print("It took you {} guesses to correctly guess the number correctly.".format(GuessesTaken))
print("Your points go up by 5! You are currently on {} points.".format(score))
restart()
def restart(): #allows the player to play again if he/she wishes
restart=input("Would you like to play again?").lower()
if restart in YES_LIST: # only occurs if the player's response is with the YES_LIST that was made earlier
main() #the game restarts
else: #
if score==0:
print("GAME OVER!", "Horrific, You didn't even manage to get a point.")
elif score>1:
print("GAME OVER!", "Good Job, You've managed to get {} points".format(score))
text_file = open(Name + " game details.txt", "w") #opens up a text file with all the game details if the player does not choose to playa again
text_file.write("Player Name: {} \nTime and date: {} \nNumber of Guesses: {} (altogether out of all the games you played) \nScore: {}".format(Name, str(currenttime), str(GuessesTaken2), str(score)))
text_file.close()
exit() #exits the game if player does not choose to play again
main() #allows the game to run