Mar-19-2018, 03:54 PM
Hi, Im new to Python and would appreciate some help. The code below doesnt work but I cant work out why.
Traceback (most recent call last):
File "F:\test monday 19th.py", line 13, in <module>
Sportsmenu()
NameError: name 'Sportsmenu' is not defined
x = 0 score = x import csv datafile = open('questions.csv', 'r') myreader = csv.reader(datafile) print ("Welcome to the Quiz, please choose a quiz number. \n 1.Sports \n 2.Geography") choice = input() if choice == "1": Sportsmenu() if choice == "2": print ("Geography") def Sportsmenu(): print ("Welcome to the Sports quiz, please choose a difficulty level. \n 1.Easy \n 2.Medium \n 1.Hard") choice = input() if choice == "1": def easysports(): if choice == "2": print ("Medium") def easysports(): datafile = open('questions.csv', 'r') myreader = csv.reader(datafile) print("Welcome to Easy Sports") for row in myreader: print(row[0]) answer1 = input("Please enter your answer ") if answer1.lower() == (row[2]): print("Correct") x = x + 1 else: print("Incorrect") print(row[1]) answer2 = input("Please enter your answer ") if answer2.lower() == (row[3]): print("Correct") x = x + 1 else: print("Incorrect") score = (x / 2) * 100 name = input("What is your name? ") print(name, x, "out of 2, your score is", score,) writefile = open("scores.csv","a") writefile.write(name + "," + score+ "\n") writefile.close() print("Score added to file")Error
Traceback (most recent call last):
File "F:\test monday 19th.py", line 13, in <module>
Sportsmenu()
NameError: name 'Sportsmenu' is not defined