佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 743|回复: 33

python

[复制链接]
发表于 26-1-2019 01:12 PM | 显示全部楼层 |阅读模式
请求各位python大神!

我是python新手,做了很多天做不出来,需要高手帮忙解决。

https://www.dropbox.com/s/6fwbaf ... u%20system.pdf?dl=0

请高手帮帮忙,谢谢
回复

使用道具 举报


ADVERTISEMENT

发表于 8-6-2019 12:50 AM 来自手机 | 显示全部楼层
问功课也至少自己动手做,把不会的,遇到问题的地方说明一下吧。



回复

使用道具 举报

 楼主| 发表于 13-6-2019 09:31 PM | 显示全部楼层
flashang 发表于 8-6-2019 12:50 AM
问功课也至少自己动手做,把不会的,遇到问题的地方说明一下吧。

这两道问题:
====================

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()


回复

使用道具 举报

发表于 13-6-2019 10:01 PM | 显示全部楼层
本帖最后由 flashang 于 13-6-2019 10:15 PM 编辑
gnow10 发表于 13-6-2019 09:31 PM
这两道问题:
====================

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 functi ...


好的。现在遇到什么问题了?
有没有 error message ? line number ?



回复

使用道具 举报

 楼主| 发表于 13-6-2019 10:52 PM | 显示全部楼层
flashang 发表于 13-6-2019 10:01 PM
好的。现在遇到什么问题了?
有没有 error message ? line number ?

总共有3个menu,我要怎么把第8题的问题取代我现在的menu 3?就是说我不要用我现在的menu 3来Search based on Name or Category substring 。我要create 一个function SearchBasedOnNameOrCategory(searchString,listOfMovies) 来search Name 或者category

我已经create了一个 在上面
def SearchBasedOnNameOrCategory(searchString, listOfMovies):
    ofTypeList=[]



然后问号那边要怎么编?


from Movie import Movie

def SearchBasedOnNameOrCategory(searchString, listOfMovies):
    ofTypeList=[]
    ????????

    return ofTypeList

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].getName())

        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].getName())
        print("Category: "+listOfMovies[index].getCategory())
        print("Description: "+listOfMovies[index].getDescription())
        print("Price: $"+str(listOfMovies[index].getPrice()))
        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].getName().lower() or usrInput.lower() in listOfMovies[index].getCategory().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].getName())
                print("Category: "+filteredList[index].getCategory())
                print("Description: "+filteredList[index].getDescription())
                print("Price: $"+str(filteredList[index].getPrice()))
                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)

'''
print("The list of movies are:")
for m in listOfMovies:
    print(m.getTitle())
'''

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":
        #create function for running menu selection 1 logic
        #include exception handling for index error
        menu1()

    elif menuSelection == "2":
        #create function for running menu selection 2 logic
        #include exception handling for index error
        menu2()

    elif menuSelection == "3":
        #create function for running menu selection 3 logic
        menu3()


回复

使用道具 举报

发表于 13-6-2019 11:57 PM | 显示全部楼层
本帖最后由 flashang 于 14-6-2019 12:20 AM 编辑

传入的有
searchString, listOfMovies
也就是说在 listOfMovies 里面找到所有 searchString 的,然后

把找到的记录放入 ofTypeList
    ofTypeList.append(listOfMovies[index])

如果需要修改资料,可以用回你写的方法
    m = Movie(name, category, description, price)
    ofTypeList.append(m)


p/s : 第七题的 PrintMovieDetails 没做?




回复

使用道具 举报

Follow Us
发表于 14-6-2019 12:15 AM | 显示全部楼层
gnow10 发表于 13-6-2019 10:52 PM
总共有3个menu,我要怎么把第8题的问题取代我现在的menu 3?就是说我不要用我现在的menu 3来Search based on Name or Category substring 。我要create 一个function SearchBasedOnNameOrCategory(sea ...

之前的 2,3 中的问题也解决了。
不过,选 2 输入 > 5 或者其他英文字母会有 error.





回复

使用道具 举报

 楼主| 发表于 14-6-2019 01:15 AM | 显示全部楼层
flashang 发表于 13-6-2019 11:57 PM
传入的有
searchString, listOfMovies
也就是说在 listOfMovies 里面找到所有 searchString 的,然后

把找到的记录放入 ofTypeList
    ofTypeList.append(listOfMovies)

如果需要修改资料,可以用回你写的 ...

我需要return ofTypeList,你看我写的对吗?

def menuSearchBasedOnNameOrCategory(searchString,listOfMovies):
    print("\n\nSearch based on Name or Category substring")
    searchString = ""
    while True:
        searchString = input("Please enter your search input\n")

        #use new function to display the movie movie details
        ofTypeList = []
        for index in range(len(listOfMovies)):
            if searchString.lower() in listOfMovies[index].getName().lower() or searchString.lower() in listOfMovies[index].getCategory().lower()==searchString:
                ofTypeList.append(listOfMovies[index])

        return ofTypeList



但是我要怎么call和运用这个function呢?有error,怎么解决这个error?

是不是我写错了?searchString那边系统说没define到

elif menuSelection == "3":

        ofTypeList=menuSearchBasedOnNameOrCategory(searchString,listOfMovies)
        print(ofTypeList)




第7题我不知道要怎么define function PrintMovieDetails(movie) ,先解决这第8题再请教你第7题





回复

使用道具 举报


ADVERTISEMENT

发表于 14-6-2019 08:12 AM 来自手机 | 显示全部楼层
本帖最后由 flashang 于 14-6-2019 08:39 AM 编辑
gnow10 发表于 14-6-2019 01:15 AM
我需要return ofTypeList,你看我写的对吗?

def menuSearchBasedOnNameOrCategory(searchString,listOfMovies):
    print("\n\nSearch based on Name or Category substring"
    searchString = ""
     ...


参考 menu2 的做法,
做一个 menu3b 来接受输入,并且用 searchString 来呼叫menuSearchBasedOnNameOrCategory。

之后就参考 menu1 的做法,把结果显示出来。
用 range 来显示也可以。



回复

使用道具 举报

 楼主| 发表于 14-6-2019 09:17 PM | 显示全部楼层
flashang 发表于 14-6-2019 08:12 AM
参考 menu2 的做法,
做一个 menu3b 来接受输入,并且用 searchString 来呼叫menuSearchBasedOnNameOrCategory。

之后就参考 menu1 的做法,把结果显示出来。
用 range 来显示也可以。

对不起大大,我不是很明白。

我现在卡在第八题这边

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("rice: $"+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 == "":
            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].getName())

        print("Enter M to return to Main Menu")

        usrInput = input("lease 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].getName())
        print("Category: "+listOfMovies[index].getCategory())
        print("Description: "+listOfMovies[index].getDescription())
        print("rice: $"+str(listOfMovies[index].getPrice()))
        print("==============================\n")
        innerMenu = ""

        innerMenu = input("Enter M to return to Previous Menu. Any key continue.\n")
        if innerMenu == "M":
            break


def menuSearchBasedOnNameOrCategory(searchString,listOfMovies):
    print("\n\nSearch based on Name or Category substring")
    searchString = ""
    while True:
        searchString = input("lease enter your search input\n")

        #use new function to display the movie movie details
        ofTypeList = []
        for index in range(len(listOfMovies)):
            if searchString.lower() in listOfMovies[index].getName().lower() or searchString.lower() in listOfMovies[index].getCategory().lower()==searchString:
                ofTypeList.append(listOfMovies[index])

        return ofTypeList
'''
        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].getName())
                print("Category: "+filteredList[index].getCategory())
                print("Description: "+filteredList[index].getDescription())
                print("rice: $"+str(filteredList[index].getPrice()))
                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)

'''
print("The list of movies are:"
for m in listOfMovies:
    print(m.getTitle())
'''

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("lease 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":

        ofTypeList=menuSearchBasedOnNameOrCategory(searchString,listOfMovies) (要怎么difine searchString?)
        print(ofTypeList)


回复

使用道具 举报

发表于 14-6-2019 09:54 PM 来自手机 | 显示全部楼层
本帖最后由 flashang 于 14-6-2019 09:57 PM 编辑
gnow10 发表于 14-6-2019 09:17 PM
对不起大大,我不是很明白。

我现在卡在第八题这边

from Movie import Movie



def menu1():
    print("\n\nDisplay all movies"
    index = 0
    usrInput = ""
    while usrInput != "M": ...


    elif menuSelection == "3":
          menu3b()

在 menu3b() 可以用回之前做的

    searchString = ""
    while True:
        searchString = input("lease enter your search input\n"

然后就可以
    ofTypeList=menuSearchBasedOnNameOrCategory(searchString,listOfMovies)

全部都是从你的 code 抄下来的,只是放在不同的地方使用。



回复

使用道具 举报

 楼主| 发表于 14-6-2019 10:17 PM | 显示全部楼层
flashang 发表于 14-6-2019 09:54 PM
elif menuSelection == "3":
          menu3b()

在 menu3b() 可以用回之前做的

    searchString = ""
    while True:
        searchString = input("lease enter your search input\n")

然 ...

elif menuSelection == "3":上面这个是要呼叫的 menuSearchBasedOnNameOrCategory(searchString,listOfMovies)不是吗?怎么用来呼叫menu3b()了呢?


你说的menu3b()是要我新建的一个function对吗?
回复

使用道具 举报

发表于 14-6-2019 10:51 PM 来自手机 | 显示全部楼层
gnow10 发表于 14-6-2019 10:17 PM
elif menuSelection == "3":上面这个是要呼叫的 menuSearchBasedOnNameOrCategory(searchString,listOfMovies)不是吗?怎么用来呼叫menu3b()了呢?


你说的menu3b()是要我新建的一个function对吗 ...

是的。因为

menuSearchBasedOnNameOrCategory(searchString,listOfMovies)

需要由被呼叫。



回复

使用道具 举报

 楼主| 发表于 14-6-2019 11:15 PM | 显示全部楼层
出来的结果为什么是这样的?当系统让我enter search input 的时候,我enter了 action 然后就出现下面这个结果了

Please input your selection
3
You have selected 3..
Please enter your search input
action


Search based on Name or Category substring
[<Movie.Movie object at 0x0000017986749BA8>, <Movie.Movie object at 0x0000017986749D30>]

Please enter your search input


code错了吗?

def menu3b():
    searchString = ""
    while True:
        searchString = input("\nPlease enter your search input\n")
        ofTypeList=menuSearchBasedOnNameOrCategory(searchString,listOfMovies)
        print(ofTypeList)


def menuSearchBasedOnNameOrCategory(searchString,listOfMovies):
    print("\n\nSearch based on Name or Category substring")


    #use new function to display the movie movie details
    ofTypeList = []
    for index in range(len(listOfMovies)):
        if searchString.lower() in listOfMovies[index].getName().lower() or searchString.lower() in listOfMovies[index].getCategory().lower()==searchString:
            ofTypeList.append(listOfMovies[index])

    return ofTypeList

    if len(ofTypeList) == 0:
        print("\n======= No results found =======")
    else:
        for index in range(len(ofTypeList)):
            print("\nMovie "+str(index+1)+" of "+str(len(ofTypeList)))
            #use new function to display the movie details
            print("==============================")
            print("Name: "+ofTypeList[index].getName())
            print("Category: "+ofTypeList[index].getCategory())
            print("Description: "+ofTypeList[index].getDescription())
            print("Price: $"+str(ofTypeList[index].getPrice()))
            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)

'''
print("The list of movies are:")
for m in listOfMovies:
    print(m.getTitle())
'''

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":
        menu3b()




应该要出现下面这样才对呀

Movie 1 of 2
==============================
Name: Mission: Impossible - Fallout
Category: Action
Description: Ethan Hunt and his IMF team, along with some familiar allies, race against time after a mission gone wrong.
Price: $20
==============================

Movie 2 of 2
==============================
Name: Incredibles 2
Category: Action
Description: Bob Parr (Mr. Incredible) is left to care for the kids while Helen (Elastigirl) is out saving the world.
Price: $12
==============================
1. Search again
2. Return to Main Menu

回复

使用道具 举报

发表于 15-6-2019 08:34 AM 来自手机 | 显示全部楼层
本帖最后由 flashang 于 15-6-2019 08:37 AM 编辑
gnow10 发表于 14-6-2019 11:15 PM
出来的结果为什么是这样的?当系统让我enter search input 的时候,我enter了 action 然后就出现下面这个结果了

Please input your selection
3
You have selected 3..
Please enter your search input
actio ...


显示结果是由 print(ofTypeList) 执行。
而 ofTypeList 是从 listOfMovies 选出来的,这两个 variable 是同样的 type。

你是怎么显示 listOfMovies 的内容呢?



回复

使用道具 举报

 楼主| 发表于 15-6-2019 10:36 AM | 显示全部楼层
flashang 发表于 15-6-2019 08:34 AM
显示结果是由 print(ofTypeList) 执行。
而 ofTypeList 是从 listOfMovies 选出来的,这两个 variable 是同样的 type。

你是怎么显示 listOfMovies 的内容呢?

你说的显示 listOfMovie的内容是指这个吗?
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)
回复

使用道具 举报


ADVERTISEMENT

发表于 15-6-2019 11:38 AM | 显示全部楼层
本帖最后由 flashang 于 15-6-2019 11:43 AM 编辑
gnow10 发表于 15-6-2019 10:36 AM
你说的显示 listOfMovie的内容是指这个吗?
listOfMovies=[]

file=open('input.txt')
lines=file.readlines()

for data [/back ...

试试看解释这几行



  1. file=open('input.txt')                        # 打开档案 input.txt
  2. lines=file.readlines()                        # 读取档案

  3. for data in lines:                            # 每一列处理:
  4.     data=data.replace("\n","")                # 把 换行 符号去除
  5.     cols=data.split("|")                      # 用 | 符号分隔行
  6.     name=cols[0]                              # 取得 name
  7.     category=cols[1]                          # 取得 category
  8.     description=cols[2]                       # 取得 description
  9.     price=cols[3]                             # 取得 price
  10.     m=Movie(name,category,description,price)  # 用取得的资料建立 数据 m,类别为 Movie
  11.     listOfMovies.append(m)                    # 在 m 加在 listOfMovies 的最后面
复制代码


这里没有 “显示” 的动作。
怎么样吧 listOfMovies 的内容正确的 print 出来呢?




回复

使用道具 举报

 楼主| 发表于 15-6-2019 09:33 PM | 显示全部楼层
flashang 发表于 15-6-2019 11:38 AM
试试看解释这几行




这里没有 “显示” 的动作。
怎么样吧 listOfMovies 的内容正确的 print 出来呢?

不行呀大大,我如果在这里放 “显示” 的动作的话,listOfMovies 的内容不是的 print 在main menu吗?


你看看我是不是编错码了




1.jpg
回复

使用道具 举报

发表于 15-6-2019 10:04 PM 来自手机 | 显示全部楼层
本帖最后由 flashang 于 15-6-2019 10:05 PM 编辑
gnow10 发表于 15-6-2019 09:33 PM
不行呀大大,我如果在这里放 “显示” 的动作的话,listOfMovies 的内容不是的 print 在main menu吗?


你看看我是不是编错码了


。。。
把 print(ofTypeList) 改了。

用 print listOfMovies 的方式来 print ofTypeList.



回复

使用道具 举报

 楼主| 发表于 15-6-2019 11:03 PM | 显示全部楼层
flashang 发表于 15-6-2019 10:04 PM
。。。
把 print(ofTypeList) 改了。

用 print listOfMovies 的方式来 print ofTypeList.

谢谢大大。第8题已经解决了。想再请教你第7题:

7.    Write a function PrintMovieDetails(movie) to print the details of the movie. It takes in a Movie object as its argument and has noreturn value.

我已经建多一个function PrintMovieDetails (movie) 在上面了,应该要怎么更改现有的code呢?






7.jpg
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 19-4-2024 06:09 PM , Processed in 0.080776 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表