Question
Python code help. I have this code working but need the code to keep score by name of who has highest number of wins. save
Python code help. I have this code working but need the code to keep score by name of who has highest number of wins.
save to file HighScore.csv only keep name & highest score to file.
Please type answer
---my code----
import random from time import sleep
#correct number variable created num = 0 #generates number at random comp_num = random.randint(1,10) print('Hello! What is your name?')
Name = input()
print('Hello, ' + Name + ', I am thinking of a number between 1 and 10.') #print('I am thinking of a number between 1 and 10... ')
#main game code def main(): #lives created guesses = 3 #correct number variable reset num = 0
while guesses >= 1: #player guesses guess = int(input('What is your guess? ')) if comp_num == guess: #if correct says well done input(' Well Done! You guessed Correctly! ') #player doesn't get told what the number is if there right num = num +1 break elif comp_num >= guess: #if guess is too low tells player #one live taken for incorrect guess guesses = guesses -1 print(' Too low! ') #player is told how many lives they have left print('You guessed incorrectly. You have',guesses,' guesses remaining. ') elif comp_num <= guess: #if guess is too high tells player #one live taken for incorrect guess guesses = guesses -1 print(' Too high! ') #player is told how many lives they have left print('You guessed incorrectly. You have',guesses,' guesses remaining. ')
def end(): #asks player if they want to play again play_again = input('Would you like to play again?[Y/N] ') while play_again.lower() == 'y': #if they do game resets and plays again if play_again.lower() == 'y': comp_num = random.randint(1,10) print(' I\'m thinking of a number guess what it is... ') main() play_again = input('Would you like to play again?[Y/N] ') if play_again.lower() == 'n': break if play_again.lower() == 'n': #if they don't game ends input(' Ok, Press enter to exit') exit()
main()
if num != 1: #if player guesses incorrectly they get told the correct awnser print('The number I was thinking of was...',comp_num,'! ')
end()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started