Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Cup
- def say_hello():
- return
- class Cup:
- def __init__(self, size, quantity):
- self.size = size
- self.quantity = quantity
- def fill(self, quantity) -> None:
- if self.quantity + quantity <= self.size:
- self.quantity += quantity
- def status(self) -> int:
- return self.size - self.quantity
- # Employee
- class Employee:
- MONTHS = 12
- def __init__(self, employee_id, first_name, last_name, salary):
- self.id = employee_id
- self.first_name = first_name
- self.last_name = last_name
- self. salary = salary
- def get_full_name(self) -> str:
- return f"{self.first_name} {self.last_name}"
- def get_annual_salary(self) -> float:
- return self.salary * Employee.MONTHS # MONTHS не принадлежи на инит, а на класа
- def get_raise_salary(self, amount: float) -> float:
- self.salary += amount
- return self.salary
- employee = Employee(744423129, "John", "Smith", 1000)
- #flower
- class Flower:
- def __init__(self, name: str, water_requirements):
- self.name = name
- self.water_requirements = water_requirements
- self.is_happy = False
- def water(self, quantity) -> None:
- if quantity >= self.water_requirements:
- self.is_happy = True
- def status(self) -> str:
- return f"{self.name} is {'' if self.is_happy else 'not '}happy"
- # hero
- class Hero:
- def __init__(self, name: str, health: int):
- self.name = name
- self.health = health
- def defend(self, damage: int) -> None or str: # Ще върне или None или string
- self.health -= damage
- if self.health <= 0:
- self.health = 0
- return f"{self.name} was defeated"
- def heal(self, amount: int) -> None: # -> None описва че връща None
- self.health += amount
- hero = Hero("Peter", 100 )
- print(hero.defend(50))
- hero.heal(50)
- # Programer
- class Programmer:
- def __init__(self, name, language, skills):
- self.name = name
- self.language = language
- self.skills = skills
- def watch_course(self, course_name, language, skills_earned):
- if self.language != language:
- return f"{self.name} does not know {language}."
- self.skills += skills_earned
- return f"{self.name} watched {course_name}"
- def change_language(self, new_language, skills_needed):
- if self.skills >= skills_needed:
- if self.language != new_language:
- previous_language = self.language
- self.language = new_language
- return f"{self.name} switched from {previous_language} to {new_language}"
- return f"{self.name} already knows {new_language}"
- return f"{self.name} needs {skills_needed - self.skills} more skills"
- # Shop
- from typing import List
- class Shop:
- def __init__(self, name, items: List[str]):
- self.name = name
- self.items = items
- def get_items_count(self):
- return len(self.items)
- shop = Shop("My Shop", ["Apples", "Bananas", "Cucumbers"])
- billa = Shop("Bolla", ["Billa stuff", "anything"])
- print(shop.items)
- print(billa.items)
- print(shop.get_items_count())
- print(billa.get_items_count())
- # Steam_user
- from typing import List
- class SteamUser:
- def __init__(self, username, games: List[str]):
- self.username = username
- self.games = games
- self.played_hours: int = 0
- def play(self, game, hours):
- if game not in self.games:
- return f"{game} is not in library"
- self.played_hours += hours
- return f"{self.username} is playing {game}"
- def buy_game(self, game) -> str:
- if game in self.games:
- return f"{game} is already in your library"
- self.games.append(game)
- return f"{self.username} bought {game}"
- def status(self):
- return f"{self.username} has {len(self.games)} games. Total play time: {self.played_hours}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement