Mar-19-2018, 03:17 PM
Sorry for repost
I am new to Python and would appreciate some greatly needed help. I am using functions with csv files and my code doesn't seem to work, please can you help:
I am new to Python and would appreciate some greatly needed help. I am using functions with csv files and my code doesn't seem to work, please can you help:
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 "//12144domain.sch/userdata$/users/staff/miahn/Desktop/Works/test.py", line 13, in <module> Sportsmenu() NameError: name 'Sportsmenu' is not defined