#๐Ÿ”’ if statement giving me error? (new to python)

8 messages ยท Page 1 of 1 (latest)

bronze pier
#

here is my code:

weight = input('Weight: ')
unit = input('(L)bs or (K)g: ')

if unit.upper() == "L":
    lbs = int(weight) * 0.45
    print(lbs)
else unit.upper() == "K":
    kg = int(weight) * 2.205
    print(kg)
 

here is the error i get in terminal

File "C:\Users\User\Downloads\projectfc\fctest.py", line 7
   else unit.upper() == "K":
        ^^^^
SyntaxError: expected ':'

why am i getting the error? why only on my "else" statment and not on my "if" statement?

clever citrusBOT
#

@bronze pier

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

vale shell
#

elif, not else. An else has no condition.

bronze pier
#

i understand it now

#

@vale shell may god bless you and your family with wonderful lives!!!

#

!close

clever citrusBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.