Jan-05-2021, 08:24 PM
(This post was last modified: Jan-05-2021, 08:25 PM by blacksword.)
(Jan-02-2021, 07:57 AM)Kakha Wrote:g = 0 m = 300 while g <= m : if g!=m : d=m-g elif g==m/2: print("We've been halfway through") print(f"Distance traveled {g}km , left to go {d}km speed 50 km/h") g = g + 50 else: print(f"Finish")
Your code says if g doesn't equal m. So it's going to check for that first. Since g is not equal to m, that if statement runs. Then you have an elif statement, which means else if. So basically if your first statement isnt true, check this statement. Since your first statement keeps being true, your elif doesn't run. You can fix this by changing elif to if. Then you have to statemens and the second statement doesn't rely on your first if statement.
g = 0 m = 300 while g <= m : if g!=m : d=m-g if g==m/2: print("We've been halfway through") print(f"Distance traveled {g}km , left to go {d}km speed 50 km/h") g = g + 50 else: print(f"Finish")