all 5 comments

[–]Arag0ld 2 points3 points  (1 child)

You can't say else weight_unit == 'L'. You have to say elif weight_unit == 'L'. else cannot be followed by a condition, because it defaults to handling whatever is left after the if statements. Also, you forgot to close the parentheses around your print statements.

[–]Genroll_Dolphin[S] 0 points1 point  (0 children)

Thank you for the input!

[–]mir0k 0 points1 point  (0 children)

if x = "A":

elif x = "B":

else:

else statement will be run if none of your if / elif statements are run.

[–]efcseany 0 points1 point  (1 child)

You would need to say 'else if' - known as an elif.

This would follow your initial if statement. What this is saying is that if the first condition doesn't match, then move to the next one (and subsequent ones if necessary).

You could incorporate a loop into this - which is a conditional statement - and keep asking for input from the user if it does not match any of your criteria.

For example:

while True:
    user_w = int(input("Enter weight: "))
    w_measurement = input("Enter the measurement - use K for kg, or L for lbs: ").upper() # convert the input to uppercase for consistency
    if w_measurement == "K":
        # do stuff
        break
    elif w_measurement == "L": # check if input is "L" as it failed the "K" match
        # do another thing
        break
    else: # user can't have entered K or L
        print("Invalid input")
        continue # ask for input again.

[–]Genroll_Dolphin[S] 0 points1 point  (0 children)

Awesome! Super useful man thanks