Currently doing the csnewbs extended task 1 (https://www.csnewbs.com/python-extended-task-1) and I've been struggling with a portion of the code which requires 3 inputs and a confirmation that they were correct. I have the 3 inputs but that's about it.
print("Hello there, welcome to Pete Porker")
while True:
e = int(input("Scotch eggs are 30p each. How many would you like to order?"))
if e == "":
continue
p = int(input("Pork Pies are 80p each. How many would you like to order?"))
if p == "":
continue
q = int(input("Quiche Tarts are £1.40 each. How many would you like to order?"))
if q == "":
continue
print("You have ordered",e,"eggs",p,"pies and",q,"quiches.")
order = input("Is this the right order?")
if order == "yes":
continue
elif order == "no":
break
There is a "continue not properly in loop" at the end and I'm not sure how to fix that either. There's an image of what the script should run at the end of the link if that helps. Thanks in advance for all the responses :)
You need to continue if break == no, otherwise break (so it's the opposite of what you've done). Your last if-then-else statement is not correctly idented (it should be 1 level further to the right). You cannot check if an integer == "" either.
Also, I wouldn't cycle the entire loop if the amount entered is empty... I'd write a simple function with an internal loop that keeps asking the same question until it gets any non-empty answer... Something like
def query(txt):
while True:
r = input(txt)
if len(r) > 0:
break
return int(r)
then your main loop would look like
while True:
e=query('enter n of eggs')
p=query('enter n of pies')
q=query('enter n of quiche')
A=input('is this enough? (y/n)')
if A=='y':
break
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments