I have the following loop which does not seem to work and I can't figure out why. Here are my variables first:
Joe_speed = 1.25 ##speed in m/s --> 4.5km/h = ((4.5*1000)/60)/60) = 1.25m/s
Jill_speed = 1.9
dog_speed = 5
total_distance = 5500 ## distance in meter between Joe and Jille when starting
JJtotal_speed = Joe_speed + Jill_speed
total_time = total_distance / JJtotal_speed ##time in seconds until meeting
totaltime = int(total_time)
Jill_distance = total_time * Jill_speed
Joe_distance = total_time * Joe_speed
dog_start = total_distance
for i in range (1, (totaltime +1) //1000) : # divided by 1000 for milliseconds
Jill_position = 0 + ((Jill_speed/1000) * i)
Joe_position = total_distance - ((Joe_speed/1000) * i)
dog_position = dog_start - ((dog_speed/1000) * i)
if dog_position == Jill_position or dog_position == Joe_position:
print("Hi")
else:
print("Ciao")
My if loop within the for loop does not seem to work however. Somehow neither "Hi" nor "Ciao" is being printed, i.e. the if loop is not happening? When I add print("...") at the end of the for loop (on the very left side on the bottom, this is being printed.
Can someone help me with this? Thanks!
Aucun commentaire:
Enregistrer un commentaire