Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- function signup()
- username = "admin"
- password = "password"
- username1 = INPUT("What is the username? ")
- password1 = INPUT("What is the assword? ")
- if username1 == username and password == password1:
- OUTPUT ("Welcome to the program!")
- mainMenu()
- elif username1 and password1:
- OUTPUT ("Incorrect Username or Password.")
- OUTPUT ("Please try again...")
- signup()
- end function
- function mainMenu()
- global gamename
- gamename = INPUT("What is your name? ")
- OUTPUT (" 1) Song Game")
- OUTPUT (" 2) Song List")
- OUTPUT (" 3) Scoreboard")
- opt = INPUT("Enter your choice: ")
- while opt >= 4:
- OUTPUT ("That is not a valid option. Please try again...")
- opt = INPUT("Enter your choice: ")
- if opt == (1):
- rand()
- elif opt == (2):
- OUTPUT ("""
- """)
- OUTPUT ("Here is the song list; ")
- OUTPUT ("It topscore()goes in the order song , artist.")
- OUTPUT ("""
- """)
- text_file = open("songs.txt", "r")
- OUTPUT (text_file.read())
- text_file.close
- mainMenu()
- elif opt == (3):
- OUTPUT ("The top 5 players are: ")
- topscore()
- end while
- end function
- function rand()
- array ListName[]
- file = open("songs.txt", "r")
- for line in file:
- ListName.append(line)
- end for
- file.close()
- songchoice(ListName)
- end function
- function songchoice(ListName)
- guesses = 1
- points = 0
- chances = 2
- OUTPUT ("------WELCOME TO THE SONG GUESSING GAME------")
- OUTPUT (" ")
- OUTPUT (" ")
- OUTPUT (" ")
- OUTPUT (" ")
- OUTPUT ("---------------------------------------------")
- while chances >0 and len(ListName) >0:
- chances = 2
- randomsong = random.choice(ListName)
- position = randomsong.find(",")
- song = randomsong[:position]
- artist = randomsong[position:]
- OUTPUT (song[0])
- OUTPUT (artist)
- choice = INPUT("Please enter your choice of song ")
- if choice == song:
- OUTPUT ("Well done, you have guessed the song correctly")
- points = points+3
- OUTPUT ("you have", points, "points!")
- ListName.remove(randomsong)
- else:
- OUTPUT ("Sorry! The song is wrong")
- chances = chances-1
- choice2 = (INPUT("What is your second attempt?" )
- if choice2 == song:
- OUTPUT ("Well done, you guessed the second time")
- points = points+1
- OUTPUT ("You have", points, "points")
- ListName.remove(randomsong)
- else:
- OUTPUT ("You guessed wrong again")
- chances = 0
- end while
- end function
- endgame()
- OUTPUT ("Game over")
- OUTPUT ("you have", points, "points")
- points = (points)
- file = open ("results.txt","a+")
- file.write(gamename)
- file.write(",")
- file.write(points)
- file.write("\n")
- file.close
- time.sleep(2)
- mainMenu()
- end function
- function something()
- OUTPUT (" ")
- OUTPUT (" ")
- while chances >0 and len(songList) >0:
- chances = 2
- randomSong = random.choice(songList)
- position = randomSong.find("by")
- song = randomSong[:position]
- artist = randomSong[position:]
- OUTPUT (song[0])
- OUTPUT (artist)
- choice = (INPUT("Please enter the choice of song, remember you only have two chances to guess")
- end function
- function topscore()
- array scoresList[]
- file = open("results.txt")
- for line in file:
- splits = line.split(",")
- score = splits[1]
- name = splits[0]
- score=(score)
- scoresList.append([score,name])
- end for
- for i in range(5):
- maximumScore = max(scoresList)
- place = i+1
- maxname = maximumScore[1]
- maxscore = maximumScore[0]
- scoresList.remove(maximumScore)
- OUTPUT ("Place number",place,"is","'"+maxname+"'","with a score of",maxscore)
- OUTPUT ("*********************************************")
- OUTPUT ("*********************************************")
- OUTPUT ("*********************************************")
- end for
- end function
- signup()
- onh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement