How can I repeat multiple inputs until you get a specified answer?

aryaan

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 :)

Girardi

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to repeat the question until you get the correct answer C#?

How can I get the user to type multiple inputs?

How can I make this not start until a valid answer in a popup box

How can i disable multiple inputs with JS?

How can I repeat inputting with the for loop numbering if the answer is not accepted?

How do you iterate a function in gdb with various inputs until you get a successful return value

How can I have bixby repeat an action but forget previous inputs?

How can I get disabled inputs in Post

How can I repeat a Firestore query until a condition is met?

How can I repeat calling a function until it returns None?

How can you get all inputs fields and the value

I can not output my answer as a multiple number it said specified cast is not valid

How to dynamically create multiple inputs and then can get their values in Angular 2?

How can I create a google scripts prompt that accepts multiple inputs

How can I use multiple refs to move focus among inputs?

How can I handle multiple mouse inputs in Java?

How can I take multiple inputs from the same line?

How can I prompt user for multiple inputs, then print summary to a file?

How can I add multiple inputs to this <div> using javascript function?

How can I generalize this to loop over multiple inputs? Bash arrays?

How can I read multiple line inputs in Python?

How i can take multiple int inputs through string builder

How can I render multiple text inputs with a for loop?

How can I add up multiple inputs in solidity?

How can I customize the output filename when multiple inputs?

How do i use fgets and strtok to get multiple inputs?

JSON parsed to ArrayList. How can I get it to repeat data in onPostExecute for multiple map markers?

How can I add an Integer to a string and get a string answer?

How can I get the correct answer show in distance (KM)?