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")
please help i cant print "We've been halfway through"
please help i cant print "We've been halfway through"
|
Jan-02-2021, 08:16 AM
Well, think about it: if
g has the value 150, then is it or is it not equal to m ?Also, you really don't need to use single letter variable names most of the time - you'd be better off using more meaningful names as that helps readability. (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") i find way g = 0 m = 300 while g <= m : if g==m/2: print("We've been halfway through") d=m-g print(f"Distance traveled {g}km , left to go {d}km speed 50 km/h") g = g + 50 else: print(f"Finish")
Ignore. Misread the code.
Jan-02-2021, 08:27 AM
Jan-02-2021, 08:29 AM
I love Python I want to learn it completely
Jan-02-2021, 02:32 PM
Then as a next step you might think about using a progress bar. Go to Pypi.org and look at Progress 1.5 and tqdm and see if you might want to download either module.
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") |
|
Users browsing this thread: 1 Guest(s)