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
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.
© 2024 OneMinuteCode. All rights reserved.