'Yes or no input else if trouble [duplicate]

I have an else if statement that will ask the user if they would like to scale the a number. If the answer is No then I want the scaler to be 0, while if the answer is yes, I would like the user to input the scaler. Every time I run the yes scaler, it still detects that the scaler is 0 and never lets the user input a number. Any suggestions?

Here is my code and output:

print ("Do you want to scale the price, Yes or No?")
answer = input("")

if answer == 'no' or 'No':
    scale = 0
elif answer == 'yes' or 'Yes':
    print("How much would you like to scale it by?")
    scale = float(input ())


print (scale)

output:

Do you want to scale the price, Yes or No?
 Yes
0


Solution 1:[1]

If you break apart your first if statement, you can rewrite what you have as:

if (answer=='no') or 'No':

Because 'No' is a non-empty string, it will always evaluate to True. So this block will always be executed.

To fix this, use in:

if answer in ('no', 'No'):
    scale = 0
elif answer in ('yes', 'Yes'):
    print("How much would you like to scale it by?")
    scale = float(input ())

Solution 2:[2]

You need to check the answer for both "no" and "No", similarly for both "yes" and "Yes".

Make the following changes in your code:

print ("Do you want to scale the price, Yes or No?")
answer = input("")

if answer == 'no' or answer == 'No':
    scale = 0
elif answer == 'yes' or answer == 'Yes':
    print("How much would you like to scale it by?")
    scale = float(input ())


print (scale)

Output:

Do you want to scale the price, Yes or No?
yes
How much would you like to scale it by?
5
5.0

Solution 3:[3]

Simple fix:

print ("Do you want to scale the price, Yes or No?")
answer = input()

if answer == 'no' or answer=='No':
    scale = 0
elif answer == 'yes' or answer== 'Yes':
    print("How much would you like to scale it by?")
    scale = float(input ())


print (scale)

'no' or 'No' would result in yes and that would be compared with answer, so that would always be true. So change it by two statement with or

Solution 4:[4]

Try this: if answer == 'no' or answer == 'No': ... elif answer == 'yes' or answer == 'Yes':

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James
Solution 2 Vishwa Mittar
Solution 3 Kalyan Reddy
Solution 4 edtheprogrammerguy