This problem is from beecrowd fuel spent c python 1017 solution solved fuel needed calculation average speed spent time consumption .3f % digits three
Fuel Spent
This problem is from beeCrowd. Here, The average speed is given as it is 12 km/L. All you have to do is to take two inputs as integers, calculate how much fuel is needed and print the value with 3 digits after the decimal points.
The formula is:
1. Take input.
2. Calculate the amount of fuel needed with this formula:
fuel_needed = (average_speed * spent_time) / consumption
3. Print the value of fuel_needed with three digits after the decimal point. In C programming using "%0.3f" will print 3 digits after the decimal point. And in Python, it is the same. The difference between this two is how you print them. Let's see the solution.
The solution in C:
#include <stdio.h>
int main() {
double consumption,fuel_needed;
int spent_time,average_speed;
scanf("%d %d",&spent_time, &average_speed);
consumption = 12.000;
fuel_needed = ((double) average_speed * (double) spent_time)/consumption;
printf("%0.3f\n",fuel_needed);
return 0;
}
The solution in Python:
spent_time = int(input())
average_speed = int(input())
consumption = 12
fuel_needed = (average_speed * spent_time) / consumption
print("%0.3f" % fuel_needed)
COMMENTS