1. Define a class bicycle
2. Properties: brand, model, year, description, weight_kg
3. Methods: name, weight_lbs, set_weight_lbs
Description:
name - take brand, model and year and put them in a string to output the name of each instance of the bicycle.
weight_lbs - convert from kilogram into pounds. 1kg = 2.2046226218 pounds
set_weight_lbs - is going to be a way that we can pass in a weight, in pounds, and have it converted into kilograms and stored in weight_kg. So you'll be able to set the weight, either by kilograms, or by pounds.
4. Instantiate 2 objects
5. Set and read properties
6. Call all methods
class bicycle:
def __init__(self):
self.brand = ""
self.model = ""
self.year = 0
self.description = ""
self.weight_kg = 0
def name(self,brand,model,year):
self.brand = brand
self.model = model
self.year = year
print(f'Brand: {self.brand}')
print(f'Model: {self.model}')
print(f'Year: {self.year}')
def weight_lbs(self,kilogram):
self.weight_kg=kilogram
pounds=kilogram*2.2046226218
print(f'{self.weight_kg} kilograms = {pounds} pounds')
def set_weight_lbs(self,pounds):
self.weight_kg=pounds/2.2046226218
print(f'{pounds} pounds = {self.weight_kg} kilograms')
def Description(self,description):
self.description = description
print(f'Description: {self.description}')
b1 = bicycle()
b1.name(input("Enter the bicycle's brand: "),
input("Enter the bicycle's model: "),
int(input("Enter the bicycle's year: ")))
b1.Description(input("Enter the description: "))
b1.weight_lbs(float(input("Enter the weight, in kilograms: ")))
b1.set_weight_lbs(float(input("Enter the weight, in pounds: ")))
b2 = bicycle()
b2.name(input("\n\nEnter the bicycle's brand: "),
input("Enter the bicycle's model: "),
int(input("Enter the bicycle's year: ")))
b2.Description(input("Enter the description: "))
b2.weight_lbs(float(input("Enter the weight, in kilograms: ")))
b2.set_weight_lbs(float(input("Enter the weight, in pounds: ")))
Comments
Leave a comment