Define a class for representing a distance

Assignment Help Python Programming
Reference no: EM132080085

Need help in simple Python form.

Define a class for representing a distance (with one attribute that represents the distance in inches). You will also need to implement the following:

1) A method that takes no extra arguments and returns the distance as a number of inches. So for example, if you created a Distance object with the command dist1 = Distance(1,2), then dist1.to_inches() should return 25 (because two feet plus one inch is 25 inches).

2) A method that takes no extra arguments and returns the distance as a number of feet. So for example, if you created a Distance object by dist1 = Distance(18), then dist1.to_feet() should return 1.5 (because 18 inches is 1.5 feet).

3) A method that takes no extra arguments and returns a tuple of two numbers representing the Distance in inches and feet (with the inches first).

So for example, if you created a Distance object with the command dist1 = Distance(30), then dist1.to_inches_and_feet() should return (6,2) (because 30 inches is equal two feet, six inches). Note that the inches part can be a float, but the feet part must be an integer (so (2.5,1) is okay, but (1, 1.5)is not).

4) A method called .__str__() which takes no extra arguments and returns a string in the format feet'inches". You'll probably want to use the .to_inches_and_feet() method you created earlier.

The .__str__() method is very similar to the .__repr__() method, only it is used to create strings that are meant to be displayed to the user instead of to another programmer. That's why the format is different. This method will automatically get used when you try to print() a Distanceobject.

So for example, if you created a Distance object with the command dist1 = Distance(30), then print(dist1) should display 2'6" on the screen. Similarly, the command str(dist1)should return the string '2\'6"'.

Reference no: EM132080085

Questions Cloud

Process of information searching in design : ENGINEERING DESIGN - DESIGN SPECIFICATION - DESIGN PARAMETERS AND INFORMATION - Teesside University - Why is knowledge of materials properties essential
What range of bit rates can be supported to have flat fading : Suppose a wireless channel has a coherence bandwidth of 100 kHz. What range of bit rates can be supported to have flat fading?
Create a subdirectory backup : Create a copy of the file in the same directory using any name you like. Create a subdirectory "backup".
Write the code below the code should be in python : Use self._rightOperand.value() to get the value of its right operand. self._operator contains the operator type.
Define a class for representing a distance : Define a class for representing a distance (with one attribute that represents the distance in inches).
Using visual basic to create a webpage that has functions : You need a form where you can add brownie points to their total points when they have done something great, or deduct points when necessary.
What are the states of nature and social contracts : What are the states of nature and social contracts in the philosophies of Hobbes, Locke, and Rousseau? How are they similar and how are they different?
Imagine it is true that humans do not have free will : Imagine it is true that humans do not have free will and are not capable of choosing which actions they have and which actions they do n
Write the list after each pass of the quick sort algorithm : Write the list after each pass of the quick sort algorithm for the following list of numbers, using the following pivot selection strategies.

Reviews

Write a Review

Python Programming Questions & Answers

  Write all the appropriate methods for the class

Create a Person class that contains the username, password, list of status updates, and list of friends. Write all the appropriate methods

  Write a python program that generates a small web site

Choose a sport or club, and get some suitable input data.. If you play a sport yourself, see if you can get some data files for your sport.

  Create a luminance histogram

In this activity, you will create a \"luminance (grey) histogram\" for a picture # chosen by the user. A luminance histogram is created by counting how many # pixels are there for each level of luminance and then by drawing a chart (typically # a ..

  How to step through and process the elements of a list

Programming in Python CS21A- Learn how to find high and low values of a list. Learn how to step through and process the elements of a list. Learn how to pass lists as arguments to a function. Learn how to wr..

  Write the python code for the problems

Topic: CS and Math. Write the python code for the following problem. Implement the modified Cholesky's algorithm by integrating

  Write test cases for code

Write file that will import the modules unittest, unittest.mock, zipfile and bb and/or parts of these modules 3. You will be mocking the following:

  Function should return a dictionary

Write a function numOccur(s), where s is a string; the function should return a dictionary whose keys are the 26 ascii letters abcdefghijklmnopqrstuvwxyz

  Write a program that should control the motion of paddle

If the player chooses to play against an automated paddle, your program should control the motion of the paddle. You can track the current position and direction of the ball to estimate whether it should move up or down from its current position.

  Implement the ransac algorithm for linear regression

You must find the observed data, threshold, also the outliers and remove them from (X,y) How exactly do i do this? please provide the code.

  How when you are typing a text message

You have all experienced how when you are typing a text message the application will provide potential words that complete what you are typing (and sometimes insist on completing them incorrectly).

  Project - expand the simulation with a class hierarchy

Project: Expand the Simulation with a Class Hierarchy. Purpose: Expand classes into a hierarchy. Introduce a View to the Model-View-Controller design pattern. Provide more functionality to the simulation

  Design and implement two related programs

CSP1150/CSP5110 Programming Principles Assignment - programming project (WordChain). You are required to design and implement two related programs

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd