Im working on a number guessing game and 4 days into it I'm beyond confused. I fix something and another problem appears. At this point its a mess. I know it's bad practice asking vague question on here but I'm desperate. My project is due in 6 hours and IDK who to turn to besides you guys. Any help without giving me the solution would be amazing.
import random
game_history = open('gameHistory.txt', 'w')
def main():
game_instructions()
start_game()
def start_game():
game_history = open('gameHistory.txt', 'w')
flag = True
while flag:
lives = 0 secret_number = random.randint(1, 30)
print(secret_number)
guess_list=[]
proceed = True
while proceed:
print('Enter a number: ')
while lives < 5 and proceed:
try:
user_guess = int(input())
guess_list.append(user_guess)
if user_guess == secret_number:
game_history.write('w' + '\n')
print('\n', 'You win.')
keep_going = input('Try again? Enter y for yes. Anything else for no: ')
if keep_going == 'y':
proceed = False
game_instructions()
start_game()
else:
end_game()
proceed = False
flag = False
elif user_guess > secret_number:
print('Nope. Lower.')
lives += 1
print('Attempts: ', lives)
elif user_guess < secret_number:
print('Nope. Higher.')
lives += 1
print('Attempts: ', lives)
if lives == 5:
game_history.write('l' + '\n')
print('Game over. Try again?', '\n', 'Correct number is: ',secret_number, '\n', 'Your guesses: ', guess_list)
keep_going = input('enter y for yes: ')
if keep_going == 'y':
proceed = False
flag = False
game_instructions()
start_game()
else:
end_game()
proceed = False
flag = False
except ValueError:
print('Please enter a number.')
flag = False
proceed = False
game_history.close()
def end_game():
print('Game Over. Goodbye.')
def game_instructions():
print('''
===========================================
*******************************************
Number guessing game!
*******************************************
This game gives you 5 attemtps at
guessing a randomly generated number
in the range of and including 1 to 30.
*******************************************
Directions:
Enter a whole number between and
including 1 and 30.
You have 5 lives! Good luck!
*******************************************
===========================================
''')
# Call main function to start program
main()