Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import random
- import time
- import re
- def unimportant():
- print ("""====Welcome to the song name guessing game====
- ==============================================
- The aim of the game is to guess the correct
- name of the song with only the first letters
- of the name of the song and the full name of
- the artists.
- ==============================================""")
- fro = open("Highscore.txt","r+")
- rand = fro.write("0")
- highscore = fro.read()
- print ("Highscore is: ",highscore)
- mainMenu()
- def mainMenu():
- starter = input ("""Would you like to:
- 1. Log In
- 2. Sign Up
- 3. Exit
- 7. Force Start
- ==============================================\n>>""")
- if starter == '1':
- print('not implemented')
- time.sleep(1.5)
- mainMenu()
- elif starter == '2':
- print('not implemented')
- time.sleep(1.5)
- mainMenu()
- elif starter == '3':
- print('Exiting...')
- time.sleep(1.5)
- sys.exit()
- elif starter == '7':
- print('Loading game...')
- time.sleep(1.5)
- main()
- else:
- print("""=====================ERROR====================
- You have entered an invalid option, Please
- try again!
- ==============================================""")
- mainMenu()
- def main():
- playerScore=0
- guessCounter = 0
- # This is where you can change the max turns and guesses
- maxTurns=999999999
- maxGuesses = 2
- while True:
- randNum = int(random.randint(0, 19))
- f=open('Songs.txt')
- linesa=f.read().splitlines()
- g=open('Artists.txt')
- linesb=g.read().splitlines()
- for turnCounter in range(maxTurns):
- randNum = int(random.randint(0, 19))
- f=open('Songs.txt')
- linesa=f.read().splitlines()
- g=open('Artists.txt')
- linesb=g.read().splitlines()
- # Pick a random song:
- print('==============================================')
- randsong =(linesa[randNum])
- randart =(linesb[randNum])
- print(randsong)
- print(randart)
- print('==============================================')
- # Prompt for a guess:
- songGuess = input("What is the song called?\n==============================================\n>> ")
- # Let the user guess until they hit the max tries:
- correctGuess = False
- while not correctGuess:
- if songGuess.lower() == randsong.lower():
- guessCounter == 0
- playerScore += 1
- correctGuess = True
- break
- else:
- # Song wasn't guessed correctly and we haven't hit
- # the max guesses yet, so try again:
- guessCounter +=1
- if guessCounter<maxGuesses:
- songGuess = input("Incorrect! Try again:\n>> ")
- else:
- break
- # We're out of the while loop, so either the song was guessed
- # correctly, or we hit the max number of guesses. Find out which:
- if correctGuess == True:
- print("Answer correct!")
- correctGuess == False
- else:
- print("""==================GAME OVER==================
- Your score was:""", playerScore, """
- ==============================================""")
- fro = open("Highscore.txt","r+")
- x = fro.read()
- xx = 0
- xx == int(x)
- if xx < playerScore:
- fro.truncate(0)
- playerScor = str(playerScore)
- fro.write(playerScor)
- else:
- break
- guessCounter==0
- restartMenu()
- return
- def restartMenu():
- restart = input("""==========Would you like to restart?==========
- 1. Yes
- 2. No
- ==============================================\n>>""")
- if restart == '1':
- main()
- elif restart == 'yes':
- main()
- elif restart == 'Yes':
- main()
- elif restart == '2':
- sys.exit(0)
- elif restart == 'no':
- sys.exit(0)
- elif restart == 'No':
- sys.exit(0)
- else:
- print("""=====================ERROR====================
- You have entered an invalid option, Please
- try again!
- ==============================================""")
- restartMenu()
- unimportant()
Add Comment
Please, Sign In to add comment