|
请问各位大神要怎么解决这两道问题:
====================
7. Write a function PrintMovieDetails (movie) to print the details of the movie. It takes in a Movie object as its argument and has no return value. This function improves maintainability.
You must use the get functions created to retrieve the movie detailsfor printing.
8. Write a function SearchBasedOnNameOrCategory(searchString, listOfMovies) to search the matching movies from a provided list of movies with the matching searchString. It takes in a searchString of type String and listOfMovie of type List as its arguments and returns result of type List.
This new function replaces the existing search code
第一个file: Movie.py
============
class Movie:
def __init__(self,name,category,description,price):
self.__name=name
self.__category=category
self.__description=description
self.__price=price
def getName(self):
return self.__name
def setName(self,name):
self.__name=name
def getCategory(self):
return self.__category
def setCategory(self,category):
self.__category=category
def getDescription(self):
return self.__description
def setDescription(self,description):
self.description=description
def getPrice(self):
return self.__price
def setPrice(self,price):
self.__price=price
def getPriceWithGST(self):
result=self.__price*1.07
return result
第二个file: MovieApp.py
===============
#我把第一个file import去第二个file
from Movie import Movie
def menu1():
print("\n\nDisplay all movies")
index = 0
usrInput = ""
while usrInput != "M":
print("\nMovie "+str(index+1)+" of "+str(len(listOfMovies)))
print("==============================")
#use new function to display the movie details
print("Name: "+listOfMovies[index].getName())
print("Category: "+listOfMovies[index].getCategory())
print("Description: "+listOfMovies[index].getDescription())
print("Price: $"+str(listOfMovies[index].getPrice()))
print("==============================")
print("Enter N for Next movie")
print("Enter P for Previous movie")
usrInput = input("Enter M to return to Main Menu\n")
# Logic for usrInput
if usrInput == "N":
index += 1
if index >= len(listOfMovies):
index = 0
elif usrInput == "P":
index -= 1
if index < 0:
index = len(listOfMovies)-1
def menu2():
print("\n\nDisplay movie full names for selection")
usrInput = ""
while True:
for index in range(len(listOfMovies)):
print(str(index+1)+". "+listOfMovies[index][0])
print("Enter M to return to Main Menu")
usrInput = input("Please enter your selection\n")
if usrInput == "M":
break
index = int(usrInput)-1
print("\nMovie "+usrInput+" of "+str(len(listOfMovies)))
print("==============================")
#use new function to display the movie movie details
print("Name: "+listOfMovies[index][0])
print("Category: "+listOfMovies[index][1])
print("Description: "+listOfMovies[index][2])
print("Price: $"+str(listOfMovies[index][3]))
print("==============================\n")
innerMenu = ""
innerMenu = input("Enter M to return to Previous Menu. Any key continue.\n")
if innerMenu == "M":
break
def menu3():
print("\n\nSearch based on Name or Category substring")
usrInput = ""
while True:
usrInput = input("Please enter your search input\n")
#use new function to display the movie movie details
filteredList = []
for index in range(len(listOfMovies)):
if usrInput.lower() in listOfMovies[index][0].lower() or usrInput.lower() in listOfMovies[index][1].lower():
filteredList.append(listOfMovies[index])
if len(filteredList) == 0:
print("\n======= No results found =======")
else:
for index in range(len(filteredList)):
print("\nMovie "+str(index+1)+" of "+str(len(filteredList)))
#use new function to display the movie details
print("==============================")
print("Name: "+filteredList[index][0])
print("Category: "+filteredList[index][1])
print("Description: "+filteredList[index][2])
print("Price: $"+str(filteredList[index][3]))
print("==============================")
usrInput = "reset"
while usrInput != "1" and usrInput != "2" :
print("1. Search again")
usrInput = input("2. Return to Main Menu\n")
if usrInput == "2":
break
listOfMovies=[]
file=open('input.txt')
lines=file.readlines()
for data in lines:
data=data.replace("\n","")
cols=data.split("|")
name=cols[0]
category=cols[1]
description=cols[2]
price=cols[3]
m=Movie(name,category,description,price)
listOfMovies.append(m)
file.close()
while True:
print("Main Menu")
print("----------")
print("1. Display all movies")
print("2. Display movie full names for selection")
print("3. Search based on Name or Category substring")
print("Q. Enter Q to quit")
menuSelection = input("Please input your selection\n")
if menuSelection == "Q":
break
print("You have selected "+menuSelection+".. ",end="")
if menuSelection == "1":
#include exception handling for index error
menu1()
elif menuSelection == "2":
#include exception handling for index error
menu2()
elif menuSelection == "3":
menu3()
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|