Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele float and int | Common data types
Learn Python from Scratch

book
float and int

Let's continue the last task.

Tehtävä

Swipe to start coding

Consider the variables from the previous chapter, and new variable velocity (in miles per hour). Your tasks are:

  1. Find out number of hours that needed to pass the distance (dist_mi) with constant speed (velocity). Save this result within time_h variable, and output the result.
  2. Calculate how many full days this trip will take using time_h variable. Save this number within time_days variable, and output the result. Note, that there you need to round up this number. You can do it by converting to integer, and adding 1 day.

Ratkaisu

# distance in km
dist_km = 4677.4
# distance in mi
dist_mi = dist_km / 1.609
# velocity (mi per h)
velocity = 50
# calculate the number of hours
time_h = dist_mi / velocity
print("Number of hours needed for the trip:", time_h)
# calculate number of full days
time_days = int(time_h / 24) + 1
print("Number of full days needed for the trip:", time_days)

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 3
# distance in km
dist_km = 4677.4
# distance in mi
dist_mi = dist_km / 1.609
# velocity (mi per h)
velocity = 50
# calculate the number of hours
time_h = _ _ _ / _ _ _
print("Number of hours needed for the trip:", _ _ _)
# calculate number of full days
time_days = _ _ _(time_h / _ _ _) + _ _ _
print("Number of full days needed for the trip:", _ _ _)

Kysy tekoälyä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt