Error handling 函数中整数的错误处理

Error handling 函数中整数的错误处理,error-handling,python-3.8,Error Handling,Python 3.8,我正在尝试创建一个菜单,将字典中的配料乘以服务次数。我已经为它创建了一个函数,但在运行时它不会定义服务的输入 这是字典 if mainoption == '1': print ('The ingredients for this dish are...') for i in dMeatballs: print (i, ":" , (dMeatballs[i] * serves))

我正在尝试创建一个菜单,将字典中的配料乘以服务次数。我已经为它创建了一个函数,但在运行时它不会定义服务的输入

这是字典

if mainoption == '1':
       
        print ('The ingredients for this dish are...')
       
        for i in dMeatballs:
                print (i, ":" , (dMeatballs[i] * serves))
      
dMeatballs={“雅各布奶油饼干”:3,“新鲜迷迭香”:1,“第戎芥末(茶匙)”:1,“牛肉或猪肉肉末(克)”:125,“干牛至(茶匙)”:0.5,“大自由放养鸡蛋/s”:1,“橄榄油(口味)”:1,“新鲜罗勒(串)”:1,“中洋葱”:1,“大蒜(丁香)”:1,“红辣椒”:0.5,“李子西红柿(克)”:100,“香醋(汤匙/s)“:1,“干意大利面或潘恩(克)”:150,“帕尔马干酪(味道)”:1}

这是整数检查器的函数

def intcheck()

serves = input("Please Enter a Number:")
try:
    serves = int(serves)
except ValueError:
    
    print('Please Use a Number')
这是在你选择主菜之后

    print (''' You have chosen Main Course,

What would you to make today''')
    
    print ('''Please choose one of the following options

                        1. Meatballs and Pasta 
                        2. Woodfired Pizza
                        3. Risotto
                        4. Chef's Soup of the Day''')
   
    mainoption = input('Please choose an option')
    
    print ('How many people are you cooking for?')
    
    intcheck()
这是它打印字典的地方

if mainoption == '1':
       
        print ('The ingredients for this dish are...')
       
        for i in dMeatballs:
                print (i, ":" , (dMeatballs[i] * serves))
      
如果你能检查一下,有什么想法尽管告诉我


谢谢

您需要从函数返回
服务
,并使用返回值。函数中指定的变量仅在该函数内部可用。