Conditional statement help


#1

Hi

I am on a course in Udemy for Python and learning conditional statements at the moment. I decided to look for other excersises online to expand my knowledge and practice practice practice. I expanded on code for an exersise and can’t figure out why it does not work:

value = float(input('input your value: '))
command = “”

while command.lower() != “f” and command.lower() != “c”:
command = input(‘convert to F or C : ‘)
if command.lower() != ‘f’ or command.lower() != ‘c’ or command.lower() != ‘x’:
print(‘Value is not f or c, type x to exit or retry’)
elif command.lower() == ‘f’:
value = (value * 9 / 5) + 32
print(f’the equivalent value in Farenheit is: {value}’)
elif command.lower() == ‘c’:
value = (value - 32) * 5 / 9
print(f’the equivalent value in Celcius is {value}’)
else:
if command.lower() == ‘x’:
print(‘thank you for using this program’)
break
print(‘wrong input try again’)

What I am trying to accomplish is if x is inputted, the else section is executed. However it does not, the section for print(‘Value is not f or c, type x to exit or retry’) keeps coming up for value x. What am I doing wrong?


#2

it would be so good if the indents work as copied. it did show before I posted. How do I ensure this sticks when posting?


#3

You could use three backticks (```) to ensure the text is in code format. A screenshot also works! (Hope this helps)