samedi 25 avril 2020

I am learning conditional statements in python.I get syntax error:Invalid statement.(Python 3.6)

This code works when I just use the "if" Statement. When I add "else" it fails.

Here is the code

def TotalDistance(Distance_A,Distance_B):
    Distance_X = (float(Distance_A) + float(Distance_B))/1000
    return Distance_X

Distance_A = input("Distance_A:")
Distance_B = input("Distance_B:")
C = str(TotalDistance(Distance_A,Distance_B))

if TotalDistance(Distance_A,Distance_B) > 1 :
    print( C + " KM")
else TotalDistance(Distance_A,Distance_B) < 1 :
    print("Distance too short")

print(TotalDistance(Distance_A,Distance_B))

and this is the error I am facing :-

File ".\myprogram_1.py", line 11
    else TotalDistance(Distance_A,Distance_B) < 1 :
                     ^
SyntaxError: invalid syntax

Aucun commentaire:

Enregistrer un commentaire