Python 对于冰淇淋口味和勺子数量,如何修复未正确执行的异常?

Python 对于冰淇淋口味和勺子数量,如何修复未正确执行的异常?,python,Python,在这个程序中,我创建了一个冰淇淋口味类和一个调味品类。还有一个Scoops类和一个Scoops错误类 问题1-如果您输入的scoops数大于3,则应打印scoops错误消息 问题2-如果您的输入未列在flavors下,则应打印flavors错误消息 对于这两种情况,如果数据与类信息不匹配,则不会显示错误消息 代码: 当前输出: 输入一种口味的冰淇淋:花生酱 输入勺子数:7 你想要个蛋筒还是碗?圆锥体 7勺花生酱放在蛋卷里 输出应该是什么: 输入一种口味的冰淇淋:花生酱 输入勺子数:2 你想要个蛋

在这个程序中,我创建了一个冰淇淋口味类和一个调味品类。还有一个Scoops类和一个Scoops错误类

问题1-如果您输入的scoops数大于3,则应打印scoops错误消息

问题2-如果您的输入未列在flavors下,则应打印flavors错误消息

对于这两种情况,如果数据与类信息不匹配,则不会显示错误消息

代码:

当前输出:

输入一种口味的冰淇淋:花生酱

输入勺子数:7

你想要个蛋筒还是碗?圆锥体

7勺花生酱放在蛋卷里

输出应该是什么:

输入一种口味的冰淇淋:花生酱

输入勺子数:2

你想要个蛋筒还是碗?圆锥体

菜单上没有花生酱

输入一种口味的冰淇淋:香草

输入勺子的数量:5

你想要个蛋筒还是碗?碗


我们没有提供那么多勺子

我想你忘了提出例外情况了吧

您正在将输入保存到变量,然后打印它


您定义的类根本不被使用。

欢迎使用SO!请拿着这本书读一读。这不是一个问题。如果您需要调试帮助,请提供一个,并尝试一次询问一个问题。我对bothI也有同样的问题。我试图使问题尽可能简单。所有的类都在那里,但它们没有启动。如果它们本质上是同一个问题,那么询问这两个问题是多余的。制作一个同时涵盖这两个方面的文档。@user14391552请善待其他人,这是一个供所有人使用的空间,你希望别人帮助你,而你这样做是不会得到帮助的。
class FlavorsError(Exception):
    def __init__ (self, message = "is not on the menu."):
        super().__init__(message)
        self.message = message
        
class Flavors(object):

    def __init__(self, Vanilla, Chocolate, Strawberry, Mint, Pistachio, Spumoni):
        self.Vanilla = Vanilla
        self.Chocolate = Chocolate
        self.Strawberry = Strawberry
        self.Mint = Mint
        self.Pistachio = Pistachio
        self.Spumoni = Spumoni

class ScoopsError(Exception):
    def __init__(self, message='We do not offer that many scoops!'):
        super().__init__(message)
        self.message = message

class Scoops(object):
    def __init__(self):
        self.count = 5
        if self.count > 3:
            raise ScoopsError()

        
class Holdings(object):

    def __init__(self, Bowl, Cone):
        self.Bowl = Bowl
        self.Cone = Cone

def main():
    
    Flavors= " "
    Scoops = " "
    Holdings = " "

    
    Flavors = input("Enter a flavor of ice cream: ")
    print()
    Scoops = int(input("Enter the number of scoops: "))
    print()
    Holdings = input("Would you like a cone or bowl? ")
    print()
    print(Scoops , "scoops of" , Flavors , "in a" , Holdings)

main()