I'm new to python and programming in general and I've written some code for a Guess the Number game in Python. It allows the user 6 attempts at guessing a random number. It works, however I am not sure if this is the best way or most efficient way of writing it and would appreciate it of I could get get some constructive feedback on it.
Code:
#Guess my Number - Exercise 3
#Limited to 5 guessesimport random attempts = 1
secret_number = random.randint(1,100)
isCorrect = False
guess = int(input("Take a guess: "))while secret_number != guess and attempts < 6:if guess < secret_number:print("Higher...")elif guess > secret_number:print("Lower...")guess = int(input("Take a guess: "))attempts += 1if attempts == 6:print("\nSorry you reached the maximum number of tries")print("The secret number was ",secret_number) else:print("\nYou guessed it! The number was " ,secret_number)print("You guessed it in ", attempts,"attempts")input("\n\n Press the enter key to exit")