- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Accumulator battery in Python
Suppose we have a mobile phone which is in "eco mode". This mode activates once your battery level reaches 20 percent. In this eco mode the battery drains two times slower than in normal mode. Now when we leave our home, we have 100% of battery. Then t minutes after we have p percent of battery left. We have to find how many minutes we have until our phone will turn off.
So, if the input is like t = 75 and p = 25, then the output will be 45
To solve this, we will follow these steps −
if p < 20, then
return 2*p*t/(120-2*p)
otherwise return (p+20) *t/(100-p)
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, t, p): if p < 20: return 2*p*t/(120-2*p) return (p+20)*t/(100-p) ob = Solution() print(ob.solve(75, 25))
Input
75,25
Output
45.0
Advertisements
To Continue Learning Please Login
Login with Google