Chicken ordering machine

Asked 2 years ago, Updated 2 years ago, 16 views

It's a chicken ordering machine. In if chicken == 0: identification error has occurred. I'm not sure if it's a code problem or a VSCODE setting problem.

class SoldOutError(Exception):
    pass

chicken = 10
waiting = 1

while(True):
    try:
        print ("Remaining Chicken: {0}").format(chicken))
        order = int(input("How many chickens would you like to order?"))
        if order > chicken:
            print ("Insufficient material")
        elif order <= 0:
            raise ValueError    
        else:
            print("[Standby Number {0}]): {0} Chicken ordered."\
            .format(waiting, order))
            waiting += 1
            chicken -= order

         if chicken == 0:
            raise SoldOutError   

except ValueError:
    print("Invalid value entered.")   
except SoldOutError:
    print("We are out of stock and no longer accept orders.")   
    break

python

2022-09-20 19:06

1 Answers

if chicken == 0 has one more blank before the if. In Python, indentation distinguishes code blocks, so you have to be careful about indentation and coding. Whether to use space characters, tap characters, and how many space characters to use, etc.

If you use vscode, installing the indent-rainbow plug-in makes the indent more clear. There are many good tools available, so get help from good tools.


2022-09-20 19:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.