-1

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   
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
  • 1
    possible duplicate of [Asking the user for input until he gives a valid response](http://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-he-gives-a-valid-response) – Kevin Apr 30 '14 at 20:12

1 Answers1

0

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.")
Zweedeend
  • 2,565
  • 2
  • 17
  • 21
  • Thak you a lot @Zweedeend,can you please explain continue and how it connects the fact that ask again for an input http://stackoverflow.com/users/2631559/zweedeend – user3573361 Apr 30 '14 at 20:32
  • In my first answer I used a 'continue', it just means 'start with the next iteration of the loop'. – Zweedeend May 01 '14 at 07:20