没有输入定义的输入?

时间:2018-04-22 02:42:01

标签: python

我正在python中编写一个代码,该代码从excel doc导入数据,以检查顾客的5位数休闲通行证是否仍然有效。这是迄今为止的代码:

import datetime
class Patron:
    def __init__(self, num, expiry, lastname, firstname, length):
        self.num = num
        self.expiry = expiry
        self.lastname = lastname
        self.firstname = firstname
        self.length = length

d = [i.strip() for i in open("names.csv")][1:]
patrons = [Patron(*x.split(",")) for x in d]

now = datetime.datetime.now()
today = str(now.year)+"-"+str(now.month)+"-"+str(now.day)

def search(x):
    n=0
    for i in patrons:
        n+=1
        if i.num == str(x):
            if today < i.expiry:
                print("Valid through "+ i.expiry)
            else:
                print("EXPIRED " + i.expiry)
            break
        elif n == len(patrons):
            print("Number not found")
        else:
            continue

目前,为了使用搜索功能,用户必须输入:

search(12345)

如何编写代码,以便程序只询问用户:

Enter number here:_____

0 个答案:

没有答案