mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-23 23:50:21 +00:00
car class added
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
from time import time, sleep
|
||||
from random import random
|
||||
|
||||
|
||||
class Car:
|
||||
def __init__(self, model: str = "Aston Martin",
|
||||
color: str = "Black",
|
||||
volume: int = 30,
|
||||
consp: int = 1):
|
||||
self.model = model
|
||||
self.color = color
|
||||
self.all_volume = volume
|
||||
self.volume = volume
|
||||
self.consumption = consp
|
||||
|
||||
def start(self) -> int:
|
||||
self.start_time = int(time())
|
||||
return self.volume // self.consumption
|
||||
|
||||
def stop(self) -> int:
|
||||
self.volume -= self.consumption * (int(time()) - self.start_time)
|
||||
return self.volume
|
||||
|
||||
def show_info(self) -> None:
|
||||
print(
|
||||
f"model: {self.model}; color: {self.color}; all volume: {self.all_volume}; volume left: {self.volume}")
|
||||
|
||||
|
||||
car = Car(volume=10)
|
||||
|
||||
time_sleep = int(car.start() * random())
|
||||
print(f"time for working: {time_sleep} seconds")
|
||||
|
||||
sleep(time_sleep)
|
||||
|
||||
car.stop()
|
||||
car.show_info()
|
||||
Reference in New Issue
Block a user