Computer Science, asked by Sirishakasetty, 1 year ago

= Assignment 3: Collaborative Assignment - Level 2
Jack and his three friends have decided to go for a trip by sharing the expenses of the fuel equally.
Write a Python program to calculate the amount (in Rs) each of them need to put in for the complete (both to and fro) journey.
The program should also display True, if the amount to be paid by each person is divisible by 5, otherwise it should display False.
(Hint: Use the relational operators in print statement.)
Assume that mileage of the vehicle, amount per litre of fuel and distance for one way are given.
Test your code by using the given sample inputs.
Verify your code by using the 2nd sample input(highlighted) given below:
Sample Input
Expected
Output
Mileage of the
vehicle (km/litre of
fuel)
Distance for
one way (kms)
Amount per
litre of fuel
(Rs)
65
12
96
260.0
True
12
40
190​

Answers

Answered by sswaraj04
24

Answer:

import math

mil=float(input("Enter mileage of vehicle "))

dis=float(input("Enter distance of one way "))

cost=float(input("Enter cost of petrol "))

print("Cost paid by each friend is ",cost*2*dis/(mil*4))

print(cost*2*dis/(mil*4*5)==math.floor(cost*2*dis/(mil*4*5)))

   

Explanation:

Here mil dis and cost stores milaege ,distance travelled and cost of fuel per litre respectively

now total fuel needed is 2*dis/mil   (distance travelled is to and fro)

total cost is (2*dis/mil)*cost

now since 4 friends are there dividing it equally

cost for each person is (2*dis*cost/mil)/3

we print it

now checking if it is divisible by 5

if it completely divisible by 5 then it should return exact value without any value after . like 25.0 34.0

floor returns e.g 34.45 gives 34.0 , 34.0 returns 34.0

so if original value and floor value are equal then it print True

your test case doesn't seem right

please check and let me know

hope it helps:-)

Answered by siddhirjadhav
23

Answer:logic cost_per_person=2×(amount per liter fuel×distance for one way/mileage)/4.

If(cost_per_person%5==0)

Print(true)

Else:

Print(false)

Explanation:

Since there 4 people travelling we divide it by 4.

It also mentioned (to and fro)hence multiply by 2 ,because (going and coming back).

In 65 rs the car travelles 12km

Hence in xrs car travelles 96km.

(65×96)/12=520

Hence you get 520 rs for one way and to and fro so multiple by 2(520)=1040

Finally 4 people hence divide by 4 (1040)/4=260rs cost_per_head

Similar questions