Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Circle
- class Circle:
- pi = 3.14
- def __init__(self, radius):
- self.radius = radius
- def set_radius(self, new_radius):
- self.radius = new_radius
- def get_area(self):
- return Circle.pi * self.radius ** 2
- def get_circumference(self):
- return Circle.pi * self.radius * 2
- # Glass
- class Glass:
- capacity = 250
- def __init__(self):
- self.content = 0
- def fill(self, ml):
- if self.content + ml > Glass.capacity:
- return f"Cannot add {ml} ml"
- self.content += ml
- return f"Glass filled with {ml} ml"
- def empty(self):
- self.content = 0
- return "Glass is now empty"
- def info(self):
- return f"{Glass.capacity - self.content} ml left"
- # Point
- class Point:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def set_x(self, new_x):
- self.x = new_x
- def set_y(self, new_y):
- self.y = new_y
- def __str__(self):
- return f"The point has coordinates ({self.x},{self.y})"
- p = Point(3, 4)
- print(p)
- # Smartphone
- from typing import List
- class Smartphone:
- def __init__(self, memory):
- self.memory = memory
- self.apps: List[str] = []
- self.is_on: bool = False
- def power(self) -> None:
- self.is_on = not self.is_on
- def install(self, app, app_memory):
- if self.is_on:
- return f"Turn on your phone to install {app}"
- if self.memory > app_memory:
- self.memory -= app_memory
- self.apps.append(app)
- return f"Installing {app}"
- return f"Not enough memory to install {app}"
- def status(self):
- return f"Total apps: {len(self.apps)}. Memory left: {self.memory}"
- # Vehicle
- class Vehicle:
- def __init__(self, mileage, max_speed: int=150):
- self.max_speed = max_speed
- self.mileage = mileage
- self.gadgets = []
- car = Vehicle(20)
- car.gadgets.append("something")
- print(car.gadgets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement