披萨堆放系统

时间:2018-11-22 13:17:41

标签: python python-3.x

我正在制作披萨点菜系统。直到我尝试使它可以让您订购多个比萨饼时,它才能起作用。我如何使用元组正确打印不带有奇怪列表语法的披萨大小和披萨顶部? 我不知道如何使用它,因为namedtuple对我来说是新的。我将披萨的详细信息放入另一个元组。 披萨的详细信息包括:大小,馅料和成本。浇头位于自己的元组中,我不知道如何在另一个元组中调用浇头时调用细节。

这很难解释,但是可以得到任何帮助!如果您不了解其中的任何内容,请回复并告诉我什么,我将尽力向您解释。

谢谢

import pygame, collections

pizzaList = []

def order():
    pizzaCost = 0.00
    pizzaSize = None
    small = ["small","£3.00"]
    medium = ["medium","£4.50"]
    large = ["large","£5.00"]
    pizzaToppings = []
    pizzaToppingsList = ["Pepperoni","Chicken","Cajun Chicken","Mushrooms","Red Onions","Sweetcorn","Ham"]
    pizzaToppingsMax = 0


    #pizza size
    print("How big would you like your pizza? ")
    pizzaSizeInput = input("Small (max 2 toppings), Medium (max 4 toppings) or Large? (max 6 toppings) ")

    if pizzaSizeInput == "Small":
        pizzaSize=small
        pizzaCost+=3.00
        pizzaToppingsMax=2

    if pizzaSizeInput == "Medium":
        pizzaSize=medium
        pizzaCost+=4.50
        pizzaToppingsMax=4

    if pizzaSizeInput == "Large":
        pizzaSize=large
        pizzaCost+=5.00
        pizzaToppingsMax=6

    pizzaToppingss(pizzaCost,pizzaSize,pizzaToppings,pizzaToppingsMax,0,1,pizzaToppingsList)

def pizzaToppingss(pizzaCost,pizzaSize,pizzaToppings,pizzaToppingsMax,pizzaToppingCount,y,pizzaToppingsList):
    Toppings = collections.namedtuple('Toppings', ['index','description','price'])

    #pizza toppings
    print("What toppings would you like? ")
    toppingsInput = input(str(pizzaToppingsList) + " ")
    pizzaToppingCount+=1
    print(str(pizzaToppingsMax - pizzaToppingCount) + " Toppings Left")

    if toppingsInput in pizzaToppingsList:
        y+=1
        pizzaToppings.append(Toppings(y, str(toppingsInput), '£0.50'))
        pizzaToppingsList.remove(toppingsInput)
        pizzaCost+=0.50

        if pizzaToppingsMax==2:
            if pizzaToppingCount==2:
                print("Here is your current pizza: ")
                pIndex = "1".ljust(5)
                pDesc = str(pizzaSize[0]).ljust(25)
                pPrice = str(pizzaSize[1]).ljust(7)
                print('{0}{1}{2}'.format(pIndex,pDesc,pPrice))

                for x in pizzaToppings:
                    index = str(getattr(x,'index')).ljust(5)
                    descr = getattr(x,'description').ljust(25)
                    price = getattr(x,'price').ljust(7)
                    print('{0}{1}{2}'.format(index,descr,price))
                finishTopping(pizzaToppings,pizzaCost,pizzaSize)

        if pizzaToppingsMax==4:
            if pizzaToppingCount==4:
                print("Here is your current pizza: ")
                pIndex = "1".ljust(5)
                pDesc = str(pizzaSize[0]).ljust(25)
                pPrice = str(pizzaSize[1]).ljust(7)
                print('{0}{1}{2}'.format(pIndex,pDesc,pPrice))

                for x in pizzaToppings:
                    index = str(getattr(x,'index')).ljust(5)
                    descr = getattr(x,'description').ljust(25)
                    price = getattr(x,'price').ljust(7)
                    print('{0}{1}{2}'.format(index,descr,price))
                finishTopping(pizzaToppings,pizzaCost,pizzaSize)

        if pizzaToppingsMax==6:
            if pizzaToppingCount==6:
                print("Here is your current pizza: ")
                pIndex = "1".ljust(5)
                pDesc = str(pizzaSize[0]).ljust(25)
                pPrice = str(pizzaSize[1]).ljust(7)
                print('{0}{1}{2}'.format(pIndex,pDesc,pPrice))

                for x in pizzaToppings:
                    index = str(getattr(x,'index')).ljust(5)
                    descr = getattr(x,'description').ljust(25)
                    price = getattr(x,'price').ljust(7)
                    print('{0}{1}{2}'.format(index,descr,price))
                finishTopping(pizzaToppings,pizzaCost,pizzaSize)

        anotherT = input("Would you like another topping? ")
        if anotherT == "yes":
            pizzaToppingss(pizzaCost,pizzaSize,pizzaToppings,pizzaToppingsMax,pizzaToppingCount,y,pizzaToppingsList)
        else:
            print("Here is your current pizza: ")
            pIndex = "1".ljust(5)
            pDesc = str(pizzaSize[0]).ljust(25)
            pPrice = str(pizzaSize[1]).ljust(7)
            print('{0}{1}{2}'.format(pIndex,pDesc,pPrice))

            for x in pizzaToppings:
                index = str(getattr(x,'index')).ljust(5)
                descr = getattr(x,'description').ljust(25)
                price = getattr(x,'price').ljust(7)
                print('{0}{1}{2}'.format(index,descr,price))
            finishTopping(pizzaToppings,pizzaCost,pizzaSize)
    else:
        print("That ingredient doesn't exist or you cannot have it.")
        pizzaToppingss(pizzaCost,pizzaToppings,pizzaToppingsMax,y)

def finishTopping(pizzaToppings,pizzaCost,pizzaSize):
    global pizzaList
    pizzaSSSList = collections.namedtuple('pizzas', ['size','toppings','cost'])
    pizzaList.append(pizzaSSSList(pizzaSize, pizzaToppings, pizzaCost))
    inp = input("Would you like another pizza?")
    if inp == "yes":
        print("yes")
        order()
    else:
        print("     ")
        print("Here is your final order: ")
        pIndex = "1".ljust(5)
        pDesc = str(pizzaSize[0]).ljust(25)
        pPrice = str(pizzaSize[1]).ljust(7)
        print('{0}{1}{2}'.format(pIndex,pDesc,pPrice))
        for x in pizzaList:
            topp = str(getattr(x,'toppings')).ljust(5)
            cost = str(getattr(x,'cost')).ljust(25)
            size = str(getattr(x,'size')).ljust(7)
            print('{0}{1}{2}'.format(size,topp,cost))

        print("The grand total is: £" + str(pizzaCost) + "0")
        exit()
def ask():
    inp = input("Hello! Would you like to order a pizza? ")
    if inp == "Yes":
        order()
    if inp == "yes":
        order()
    else:
        ask()

ask()

1 个答案:

答案 0 :(得分:0)

如果您使用的是python3,则可以使用拆包运算符和print方法默认情况下使用空格分隔符来打印列表。

>>> print(*[0, 1, 2])
0 1 2

您还可以指定分隔符

>>> print(*[1, 'pizza', 'peperoni'], sep=' ==> ')
1 ==> pizza ==> peperoni