1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
crimeas [40]
2 years ago
5

Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/kmâ

pick one) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a function drive that simulates driving the car for a certain distance, reducing the fuel level in the gas tank, and functions get_gas, to return the current fuel level, and add_gas, to tank up. Sample usage:Car my_beemer(29); // 29 miles per gallonmy_beemer.add_gas(20); // Tank 20 gallonsmy_beemer.drive(100); // Drive 100 milescout << my_beemer.get_gas() << "\n"; // Print fuel remaining
Computers and Technology
1 answer:
zvonat [6]2 years ago
3 0

Answer:

class Car(object):

   fuel = 0

   def __init__(self, mpg):

       self.mpg = mpg

   def drive(self, mile):

       if self.fuel * self.mpg >= mile:

           self.fuel -= mile / self.mpg

       else:

           print(f"get gas for your {self}")

       print(f"Fuel remaining: {self.fuel}")

   #classmethod

   def get_gas(cls):

       cls.fuel += 50

   #classmethod

   def add_gas(cls, gallon):

       if cls.fuel + gallon > 50:

           cls.fuel += 10

       else:

           cls.fuel += gallon

gulf = Car(20)

gulf.get_gas()

gulf.drive(200)

Explanation:

The Car class is defined in Python. Its drive method simulates the driving of a car with fuel that reduces by the miles covered, with efficiency in miles per gallon. The get_gas and add_gas methods fill and top up the car tank respectively.

You might be interested in
Declare an array named a of 10 elements of type int and initialize the elements (starting with the first) to the values 10, 20,
kherson [118]

Answer:

int a[10] = {10,20,30,40,50,60,70,80,90,100};

Explanation:

In the above statement, we declare the integer data type array variable that is 'a' then, pass its index value that is 10 which means it contains only 10 values and initialize the components of the array variable that is starting with 10 and end at 100 in the difference of 10. So, the following declaration is correct according to the statement.

5 0
3 years ago
"Write an iterative function iterPower(base, exp) that calculates the exponential baseexp by simply using successive multiplicat
sp2606 [1]

Answer:

I am writing the function using Python. Let me know if you want the program in some other programming language.            

def iterPower(base, exp):    

    baseexp = 1

    while exp > 0:

        baseexp = baseexp*base

        exp= exp - 1

    return baseexp

base = 3

exp = 2

print(iterPower(base, exp))

Explanation:

  • The function name is iterPower which takes two parameters base and exp. base variable here is the number which is being multiplied and this number is multiplied exponential times which is specified in exp variable.
  • baseexp is a variable that stores the result and then returns the result of successive multiplication.
  • while loop body keeps executing until the value of exp is greater than 0. So it will keep doing successive multiplication of the base, exp times until value of exp becomes 0.
  • The baseexp keeps storing the multiplication of the base and exp keeps decrements by 1 at each iteration until it becomes 0 which will break the loop and the result of successive multiplication stored in baseexp will be displayed in the output.
  • Here we gave the value of 3 to base and 2 to exp and then print(iterPower(base, exp)) statement calls the iterPower function which calculates the exponential of these given values.
  • Lets see how each iteration works:
  • 1st iteration

baseexp = 1

exp>0 True because exp=2 which is greater than 0

baseexp = baseexp*base

               = 1*3 = 3

So baseexp = 3

exp = exp - 1

      = 2 - 1 = 1    

exp = 1

  • 2nd iteration

baseexp = 3

exp>0 True because exp=1 which is greater than 0

baseexp = baseexp*base

               = 3*3 = 9

So baseexp = 9

exp = exp - 1

      = 1-1 = 0    

exp = 0

  • Here the loop will break now when it reaches third iteration because value of exp is 0 and the loop condition evaluates to false now.
  • return baseexp statement will return the value stored in baseexp which is 9
  • So the output of the above program is 9.
5 0
2 years ago
What are the reason of making computer virus.​
GenaCL600 [577]

Answer:

Some computer experts create computer viruses to prove certain a process will work

Explanation:

6 0
2 years ago
Read 2 more answers
Which of the following Office Online apps is most effective for creating spreadsheets?
navik [9.2K]
The answer is C Excel. Excel allows you to make spreadsheets.

Hope this helps :-)
4 0
3 years ago
Read 2 more answers
In minecraft Education Edition what is the crafting recipe for Balloons and Glow sticks?
schepotkina [342]

Answer

sorry I only know how to make balloons :(

Explanation:

For the balloons the recipe that one is:

- you will need 6 latex

To make latex you will need two different elements one is 5 Carbon and the other one is 8 Hydrogen ( don't use crafting table to do it use the compound creator)

-Dye ( whatever color you want)

-Helium

-lead

Instructions

on the crafting table the latex will go on the sides (3 on the left and 3 on the right). The dye goes on top, the Helium in the middle and the lead at the bottom and there you go a balloon

8 0
3 years ago
Read 2 more answers
Other questions:
  • Respecting yourself and others, educating yourself and connecting with others, and protecting yourself and others are all aspect
    9·2 answers
  • write a program using if condition and print fail and try again if student marks are less than 33 using if condition and print f
    5·1 answer
  • Type dig www.example A in order to get the IP address of www.example. What’s the TTL of the A record returned in the response? W
    9·1 answer
  • Assume the availability of class named DateManager that provides a static method, printTodaysDate, that accepts no arguments and
    11·1 answer
  • Anyone got the edmentum computer programming post test answers?
    6·1 answer
  • The following is a sequence of undo-log records written by two transactions T and U: &lt; START T&gt;; ; &lt; START U&gt;; ; ; ;
    8·1 answer
  • The following is a true example of a computer: A. Toyota Camry
    12·1 answer
  • Help me
    5·1 answer
  • Difference between multi-national and global company​
    11·2 answers
  • What are the two access modes that are used when opening a file for input and output when pickling?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!