Skip to content Skip to sidebar Skip to footer

If Else Statment Not Following The Elif Correctly

I was given the assignment to make a program that takes user input (a temperature) and if the temperature is Celsius convert to Fahrenheit and Vice versa. The problem is that when

Solution 1:

The following:

ifmyscale== "f" or "F":

should read:

ifmyscale== "f"ormyscale== "F":

or

if myscale in("f", "F"):

or (if your Python is recent enough to support set literals):

if myscale in {"f", "F"}:

The same goes for

elif: myscale == "c" or "C":

Also, there is an extraneous colon after the elif.

What you have now is syntactically valid but does something different to what is intended.

Solution 2:

Here is your problem:

elif: myscale == "c" or "C":

Note the : after the elif

You also should use in as noted by the other answers.

Post a Comment for "If Else Statment Not Following The Elif Correctly"