Car Fuel Check

Car Fuel Check

Easy Programming Interview OOP 25 views
Explanation Complexity

Problem Statement

Distance d, mileage m (km per litre) and fuel f are provided. Create Car class can_reach(d) returns YES if fuel enough else NO.

Input Format

One line: d m f.

Output Format

YES or NO.

Example

120 15 5
YES

Constraints

0

Input / Output Format

Input Format
One line: d m f.
Output Format
YES or NO.
Constraints
0

Examples

Input:
120 15 5
Output:
YES

Example Solution (Public)

Programming Interview
import sys
p=sys.stdin.read().strip().split()
if len(p)<3: sys.exit(0)
d=float(p[0]); m=float(p[1]); f=float(p[2])
class Car:
  def __init__(self,mileage,fuel):
    self.mileage=mileage
    self.fuel=fuel
  def can_reach(self,dist):
    return 'YES' if self.mileage*self.fuel>=dist else 'NO'
print(Car(m,f).can_reach(d))

Official Solution Code

import sys
p=sys.stdin.read().strip().split()
if len(p)<3: sys.exit(0)
d=float(p[0]); m=float(p[1]); f=float(p[2])
class Car:
  def __init__(self,mileage,fuel):
    self.mileage=mileage
    self.fuel=fuel
  def can_reach(self,dist):
    return 'YES' if self.mileage*self.fuel>=dist else 'NO'
print(Car(m,f).can_reach(d))
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.