Question

2. (a) Implement a class Student. For the purpose of this exercise, a student has a name and a total quiz score. Supply an apBy Python 3 please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 3:

Code:

class Car: def _init__(self, efficiency): Constructor to initialize efficiency and set initial fuel level to self.efficiency

Code as text:

class Car:

def __init__(self, efficiency):

''' Constructor to initialize efficiency and set initial fuel level to 0 '''

self.efficiency = efficiency

self.fuellevel = 0

def addGas(self, fuel):

''' method to add gas to car '''

self.fuellevel += fuel

def drive(self, distance):

''' method to simulate driving a certain distance '''

fuelused = distance/self.efficiency

self.fuellevel -= fuelused

def getGasLevel(self):

''' method to return the current fuel level '''

return self.fuellevel


if __name__ == "__main__":

myHybrid = Car(50) # 50 miles per gallon

myHybrid.addGas(20) # Tank 20 gallons

myHybrid.drive(100) # Drive 100 miles

print(myHybrid.getGasLevel()) # Print fuel remaining

Sample run:

| 18.0

Add a comment
Know the answer?
Add Answer to:
By Python 3 please 2. (a) Implement a class Student. For the purpose of this exercise,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python code DC Final Project Implement a class Car with the following properties. A car has...

    python code DC Final Project Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. The following two lines are written in a File called FuelEffic.txt (you have to read these from the txt file) Miles per gallon: 20 Tank Size (in gallons): 25 Therefore, based on these...

  • In JAVA In this assignment you will use a class Car to represent a car that travels to various de...

    In JAVA In this assignment you will use a class Car to represent a car that travels to various destinations. Your car has a fuel economy rating of 32.3 miles per gallon. The gas tank holds 19.5 gallons. Your program will need to simulate two trips: 1) BC to Yosemite Valley, and 2) BC to Washington, D.C.. For each trip you will start with a full tank of gas. The output should look as follows. Trip one: Bakersfield College to...

  • please help me add on this java code to run public class CarHwMain public static void...

    please help me add on this java code to run public class CarHwMain public static void main(String args 1/ Construct two new cars and one used car for the simulation Cari carl = new Car W"My New Mazda", 24.5, 16.0); Car car2 = new Cart My New Ford" 20.5, 15.0) Cari car) - new Cari ("My Used Caddie", 15.5, 16.5, 5.5, 1/ ADD CODE to completely fill the tanks in the new cars and off the used cars ton //...

  • I NEED ALL QUESTIONS OR ELSE THUMBS DOWN! C++ Implement a structure Employee. An employee has...

    I NEED ALL QUESTIONS OR ELSE THUMBS DOWN! C++ Implement a structure Employee. An employee has a name (a char *) and a salary (a double). Write a default constructor, a constructor with two parameters (name and salary), and methods char* getName() double getSalary() to return the name and salary. Write a small global function TestEmployee() to test your structure. Creating a new employee. Please type the name: Larry Bird Please specify the salary: 200000 New employee has been created....

  • Implement a class Student. For the purpose of this exercise the student has a name and...

    Implement a class Student. For the purpose of this exercise the student has a name and a total quiz score. The appropriate constructors and methods are: getName(), addQuiz(int Score), getTotalScore(), getAverageScore(). Include a toString that prints the students name, the quiz average and the number of quizzes taken. Override the equals method in a meaningful way. You must compare more than one variable in the equals method.

  • Please help with PYTHON exercise 1 below: Write a program Sores.py to process a student's homework...

    Please help with PYTHON exercise 1 below: Write a program Sores.py to process a student's homework scores. Ask user to enter the homework scores for a student and save the scores in a list. Loop through the list to find the total score and the lowest score. (Do not use built-in function, sum and min. You need to write a loop to process the scores). Calculate the raw average score and modified average score (after dropping the lowest score). Print...

  • PYTHON Exercise #2: Design and implement class Radio to represent a radio object. The class defines...

    PYTHON Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. 1. A private variable of type int named station to represent a station number. Set to 1. 2. A private variable of type int named volume to represent the volume setting. Set to 1. 3. A private variable of type boolean named on to represent the...

  • SOLVE IN PYTHON: Exercise #2: Design and implement class Radio to represent a radio object. The c...

    SOLVE IN PYTHON: Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. A private variable of type int named station to represent a station number. Set to 1. A private variable of type int named volume to represent the volume setting. Set to 1. A private variable of type boolean named on to represent the radio...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • python 3 question Project Description Electronic gradebooks are used by instructors to store grades on individual assignments and to calculate students’ overall grades. Perhaps your instructor uses gr...

    python 3 question Project Description Electronic gradebooks are used by instructors to store grades on individual assignments and to calculate students’ overall grades. Perhaps your instructor uses gradebook software to keep track of your grades. Some instructors like to calculate grades based on what is sometimes called a “total points” system. This is the simplest way to calculate grades. A student’s grade is the sum of the points earned on all assignments divided by the sum of the points available...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT