Last active
August 15, 2021 08:01
-
-
Save jatinsharrma/7b94beef91d5792758a74af8397c3e8e to your computer and use it in GitHub Desktop.
The road transport corporation (RTC) of a city wants to know whether a particular bus-route is running on profit or loss.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The road transport corporation (RTC) of a city wants to know whether a particular bus-route is running on profit or loss. | |
| # Assume that the following information are given: | |
| # Price per litre of fuel = 70 | |
| # Mileage of the bus in km/litre of fuel = 10 | |
| # Price(Rs) per ticket = 80 | |
| # The bus runs on multiple routes having different distance in kms and number of passengers. | |
| # Write a function to calculate and return the profit earned (Rs) in each route. Return -1 in case of loss. | |
| # Also write the pytest test cases to test the program | |
| def calculate(distance,no_of_passengers): | |
| cost = 0 | |
| cost = 70 * distance/10 | |
| rest = 0 | |
| rest = no_of_passengers * 80 | |
| if cost <= rest : | |
| return abs(cost - rest) | |
| else : | |
| return -1 | |
| distance=20 | |
| no_of_passengers=50 | |
| print(calculate(distance,no_of_passengers)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
3860.0