Question

I have all the neccesary codes in order to perfom the actions that are neccessary when someone presses the customer or product value.All i am asking is to help me find a way to repeat the question of asking a value as an input if it is not one of the three optons(customers or products or q).

In addition how to repeat the whole procedure until the value that is given is q

And finally how to stop the progrm if it gives the value q.

The program should like this:

Welcome to the Global Grocery, where world leaders do their shopping!

To view sales information for each customer type 'customers'.
To view sales information for each product type 'products'.
To quit type 'q'.
clients

Please choose 'customers', 'products', or 'q' to quit.
items

Please choose 'customers', 'products', or 'q' to quit.
customers

barakobama
----------
cereal: 9.21 crisps: 1.09 potatoes: 2.67 parsley: 0.76 sugar: 1.98

vladimirputin
-------------
bread: 0.66 parsley: 1.33 milk: 2.87

Please choose 'customers', 'products', or 'q' to quit.
q

Thank you for visiting, come again!

Until now i only have this:

print("Welcome to the Global Grocery, where world leaders do their shopping!","\n") 

print("To view sales information for each customer type \'customers\'.") 
print("To view sales information for each product type \'products\'.")
print("To quit type \'q\'.")
data=input("")

while data!="customers" or data!="products" or data!="q":
    print("Please choose \'customers\', \'products'', or \'q\' to quit.")
    data=input("")

    if data=="customers":

    elif data="products":

    else:
         print("Thank you for visiting, come again!")
         break   
Was it helpful?

Solution

I think this is what you are looking for:

#!/usr/bin/env python3

print("Welcome to the Global Grocery, where world leaders do their shopping!","\n")

print("To view sales information for each customer type \'customers\'.")
print("To view sales information for each product type \'products\'.")
print("To quit type \'q\'.")

while True:  # Keep going forever until a 'break' statement is met
    data = input("")
    if data == "q":
        print("Good bye!")
        break  # end the 'while' loop
    elif data == "customers":
        print("Ok, customer stuff")
    elif data == "products":
        print("Ok, product stuff")
    else:  # A non-valid option must have been selected
        print("Please choose \'customers\', \'products'', or \'q\' to quit.")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top