Question: NEED HELP ASAP I KEEP GETTING A SYNTAX ERROR PLEASE HELP!!!!! #Get the data def openFile(): validFile = False while validFile == False: fname =
NEED HELP ASAP
I KEEP GETTING A SYNTAX ERROR PLEASE HELP!!!!!
#Get the data def openFile(): validFile = False while validFile == False: fname = input("Enter the file name: ") try: movieFile = open(fname, 'r') validFile = True except IOError: print("Invalid filename, please try again...") return movieFile
def getData(): movieFile = openFile() titleList = [] genreList = [] runtimeList = [] ratingList = [] studioList = [] yearList = [] for line in movieFile: #Get rid of first line line = line.strip() title, genre, runtime, rating, studio, year = line.split(',') titleList.append(title) genreList.append(genre) runtimeList.append((runtime)) #add int ratingList.append(rating) studioList.append(studio) yearList.append((year)) #add int return titleList, genreList, runtimeList, ratingList, studioList, yearList
def genreSearch(titleList, genreList, runtimeList, ratingList, studioList, yearList): genre = input("Enter genre: ") for i in range(len(genreList)): if genre == genreList[i]: print(titleList[i], genreList[i], runtimeList[i], ratingList[i], studioList[i], yearList[i]) return
def ratingSearch(titleList, genreList, runtimeList, ratingList, studioList, yearList): rating = input("Enter rating: ") for i in range(len(ratingList)): if rating == ratingList[i]: print(titleList[i], genreList[i], runtimeList[i], ratingList[i], studioList[i], yearList[i]) return
def studioSearch(titleList, genreList, runtimeList, ratingList, studioList, yearList): studio = input("Enter studio: ") longest = 0 pos = 0 for i in range(len(studioList)): if studio == studioList[i]: length = int(runtimeList[i]) if length > longest: longest = length pos = i print(titleList[pos], genreList[pos], runtimeList[pos], ratingList[pos], studioList[pos], yearList[pos]) return def titleSearch(titleList, genreList, runtimeList, ratingList, studioList, yearList): title = input("Enter title: ") for i in range(len(titleList)): if title == titleList[i]: print(titleList[i], genreList[i], runtimeList[i], ratingList[i], studioList[i], yearList[i]) return
def averageRunYear(): return
def sortRuntime(runtimeList): indexList = [] for i in range(0, len(runtimeList)): min = i for j in range(i + 1, len(runtimeList)): # comparison if runtimeList[j] < runtimeList[min]: min = j #swap runtimeList[i], runtimeList[min] = runtimeList[min], runtimeList[i] indexList.append(runtimeList.index(i)) print (indexList) return indexList #create copy of runtime list #make an index list #sort the index list as you sort the runtime list so they keep the same index return
userCall = 0
#def menu(): # return choice def main(): titleList, genreList, runtimeList, ratingList, studioList, yearList = getData() choice = 0 while choice != 7: print("") if userCall == 0: print("Please choose one of the following options:") print("1 -- Find all films of a certain genre") print("2 -- Find all films with a certain rating") print("3 -- Find the longest film made by a specific studio") print("4 -- Search for a film by title") print("5 -- Find average runtime of films made in a given year range") print("6 -- Sort all lists by runtime and write the results to a new file") print("7 -- Quit") break while True: try: choice = int(input("Choice ==>: ")) break try: if choice == 1: genreSearch(titleList, genreList, runtimeList, ratingList, studioList, yearList) elif choice == 2: ratingSearch(titleList, genreList, runtimeList, ratingList, studioList, yearList) elif choice == 3: studioSearch(titleList, genreList, runtimeList, ratingList, studioList, yearList) elif choice == 4: titleSearch(titleList, genreList, runtimeList, ratingList, studioList, yearList) elif choice == 5: averageRunYear(titleList, genreList, runtimeList, ratingList, studioList, yearList) elif choice == 6: sortRuntime(runtimeList) if choice == 7: #End program return
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
