如何删除不需要的支票

时间:2016-02-17 20:27:43

标签: python

在我的代码中,我有一个检查功能,可以确保用户输入正确的代码。唯一的事情是它发生两次;一旦它向用户询问它以便验证它,并且当需要从文本文件中检索某些东西时再次询问它。

def gtin8check():
    valid = False
    while not valid:
        gtin8 = input("Please enter your 8 digit GTIN product code.") #Prompt user for the GTIN code
        if gtin8.isdigit(): #Numbers will only be accepted as an answer, if the user types in letters they will be asked to type it out again
            if len(gtin8) != 8:
                print("Please enter 8 digits, numbers only.")
                gtin8check()
            else:
                answer = ((int(gtin8[0])*3)+(int(gtin8[1]))+(int(gtin8[2])*3)+(int(gtin8[3]))+(int(gtin8[4])*3)+(int(gtin8[5]))+(int(gtin8[6])*3)+(int(gtin8[7]))) #Multiply the first 7 digits by 3 and 1 alternately
                if answer/10 == int(answer/10):
                    print("GTIN Code is valid.") 
                    valid = True
                else:
                    print("This GTIN Code is not valid, please re-enter a valid code.")
                    valid = False
        else:
            print("Please enter 8 digits, numbers only.")
            valid = False
gtin8check()


def receipt():
    food = input("Enter the product code for the item you want.")

    fi = open("data.txt","r")
    info = fi.readlines()
    fi.close()

    price = (li.split(":")[2])

    item = False 
    for li in info:
        if(li.split(":")[0].lower() == food):
            print(li.split(":")[1])
            item = True
            quantity = input("How many do you want?")        
            print("£" + quantity)
receipt()

我如何删除其中一张支票并将其合并到另一张支票中?

0 个答案:

没有答案