python中最小输入和最大输入之间的范围

时间:2018-01-15 10:43:14

标签: python-3.x

我必须通过输入最小和最大的“电影持久性”来制作功能,客户端会打印出持续在该范围内的每部电影。现在,当我输入(作为一个最小的)两位数字和(作为一个最大的)三位数时,它总是说“没有找到电影”,但是例如,当我输入时(对于最小和最大)两位数或三位数字,范围有效,并打印出属于该范围的电影。我做到了这一点:

list_of_movies = []
def movie_list():
    with open("film.txt","r") as f:
        all_h = ["name","genre","lasting","director","main role","country","year","description"]
        for r in f.readlines():
            dicct = {}
            bla = r.strip().split("|")
            count = 0
            for i in bla:
                dicct[all_h[count]] = i
                count += 1
            list_of_movies.append(dicct)
movie_list()
def lasting():
    x=False
    lasting_min = input("Input minimal lasting: ")
    lasting_max = input("Input maximal lasting: ")
    for r in list_of_movies:
        if r["lasting"] >= lasting_min and r["lasting"] <= lasting_max:
            print()
            print("Name of the movie: ", r["name"])
            print("Genre: ", r["genre"])
            print("Lasting: ",r["lasting"],"minutes")
            print("Director: ",r["director"])
            print("Main roles: ",r["main role"])
            print("Country: ",r["country"])
            print("Year: ",r["year"])
            print("-------------------------------")
            x=True
    if x==True:
        print()
    else:
        print()
        print("No movie was found. ")
        print()
lasting()

顺便说一下,我制作了词典和列表,所以每次我需要的时候都不需要打开txt文件。

0 个答案:

没有答案