0

For the first input of my program,Brand,the program does not ask the user to re-enter the input when the input is wrong,it just moves on to the next input. For the rest of the input the program runs as intended.

I've tried to search online but still could not find a solution to solve the problem.

exit=input('Press any button to continue,press Q or q to exit')
if exit=='q' or exit=='Q':
    break
else:
    Brand = input("Enter the perfume brand: ")
    while True:
        try:
            while True:
                Scent = input("What type of scents you looking for (Floral/Woody/Oriental): ").lower()
                if Scent == 'floral'or Scent == 'woody' or Scent == "oriental":
                    break
                else:
                    print('Invalid perfume scent')
                    continue
            while True:
                Type = input("What type of perfume you like it in (Eau De Parum/Eau De Toilette/Eau De Cologne): ").lower()
                if Type == 'eau de parum':
                    break
                else:
                    print('Invalid type of perfume')
                    continue
            Quantity = int(input("Enter quantity of the perfume :"))
            price = float(input("Enter price of the perfume:$ "))
            print("Brand:",Brand)
            print("Scents:",Scent)
            print("Type:",Type)
            print("Quantity:",Quantity)
            print("price:$",format(price,'.2f'))
        except:
            print('Invalid perfume')

The expected result of the program is to check at every input if the right input is entered otherwise the user have to re-enter the input until it is the correct one.

Sorry if I could not clearly explain what my program wants to achieve

  • Can you provide a sample output that you expect from your program and what you are getting as the output right now? – sudo97 Jul 03 '19 at 11:27
  • Press any button to continue,press Q or q to exit Enter the perfume brand: q Invalid perfume brand What type of scents you looking for (Floral/Woody/Oriental): q Invalid perfume scent What type of scents you looking for (Floral/Woody/Oriental): floral What type of perfume you like it in (Eau De Parum/Eau De Toilette/Eau De Cologne): q Invalid type of perfume What type of perfume you like it in (Eau De Parum/Eau De Toilette/Eau De Cologne): eau de parum – user305762 Jul 03 '19 at 11:32
  • The first part of the program isnt working as intended or is it because I dont have inputs for Brand thats why whatever the input is the program continues? – user305762 Jul 03 '19 at 11:34
  • 2
    Possible duplicate of [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – Masoud Jul 03 '19 at 11:35

0 Answers0