0

I cannot differentiate two different string values when I input them into an if/elif/else statement. In my code, the user is asked if they would like to tip or not when ordering from a menu. But it always shows up as asking for the value of the tip even when I say no. I wanted to know what I was doing wrong and how to change it. Thanks in advance.

tax = (selection * 0.05)
price_without_tip = float(selection + (tax * selection))
tip_Selection = str(input('Enter the Word Yes or No exactly to choose if you would like 
to tip: '))
percent_Or_Fixed = input('Enter the word Percent or Fixed exactly to choose your 
preferred form of Tip: ')

if tip_Selection == 'Yes':
    print(percent_Or_Fixed)
elif tip_Selection == 'No':
    print(price_without_tip)
else:
    print('Invalid Response. Please Restart Order')

percent = 0.18
fixed = 2.00

if percent_Or_Fixed == 'Percent':
    print ((selection + (selection * percent) + tax))
elif percent_Or_Fixed == 'Fixed':
    print(selection + fixed + tax)
  • Welcome to Stack Overflow. The `if`/`elif`/`else` in the code *works perfectly fine*. It's just that *after that*, there is nothing to prevent the code from moving on. `if` cannot make code repeat; that's what loops are for. Anyway: please read [ask] and note well that this is **not a discussion forum**. We are looking for a clear, specific question, asked directly - not "I was wondering...", and [not](https://meta.stackoverflow.com/questions/288160/) your thanks. – Karl Knechtel Sep 21 '22 at 19:39
  • Also the order of your code is somewhat wrong the if stament should be before the input of the amout – Sheyteo Sep 21 '22 at 19:41
  • Your code runs top to bottom so by having `percent_Or_Fixed = input(...)` on the fifth line it executes before the if-else statements. If you want to execute that input when a condition is met then move the input under the correct condition. – It_is_Chris Sep 21 '22 at 19:41

0 Answers0