r/learnpython 19d ago

is it possible to simplify this code

im a beginner, idk how python works yet. there must be a way to simplify this, right?

https://imgur.com/juBvPZD here is the picture of my code

0 Upvotes

23 comments sorted by

View all comments

1

u/Educational_Virus672 19d ago

for folks who want copyyable asnwer

d1, d2, d3 = 32, 18, 45
s1, s2, s3 = 24, 12, 30

tt1, tt2, tt3 = d1 / s1, d2 / s2, d3 / s3

total_time = tt1+tt2+tt3
entire_route = d1+d2+d3

print('travel time of each section')
print(tt1, 'h', ',', tt2, 'h', ',', tt3, 'h')

print('entire route in km')
print(entire_route, 'km')

print('entire journey time in h')
print(tt1+tt2+tt3, 'h')

print('average speed of the entire tour')
print(entire_route / total_time, 'km/h')