본문 바로가기

CLASS8

0124. Regular Ball Super Ball Create a class Ball. Ball objects should accept one argument for "ball type" when instantiated. If no arguments are given, ball objects should instantiate with a "ball type" of "regular." ball1 = Ball() ball2 = Ball("super") ball1.ball_type #=> "regular" ball2.ball_type #=> "super" Solution: class Ball(object): def __init__(self, type: str = "regular") -> None: self._type = type @property def ba.. 2023. 1. 24.
0116. OOP: Object Oriented Piracy Ahoy matey! You are a leader of a small pirate crew. And you have a plan. With the help of OOP you wish to make a pretty efficient system to identify ships with heavy booty on board! Unfortunately for you, people weigh a lot these days, so how do you know if a ship is full of gold and not people? You begin with writing a generic Ship class / struct: class Ship: def __init__(self, draft, crew): s.. 2023. 1. 16.
0104. Sleigh Authentication Christmas is coming and many people dreamed of having a ride with Santa's sleigh. But, of course, only Santa himself is allowed to use this wonderful transportation. And in order to make sure, that only he can board the sleigh, there's an authentication mechanism. Your task is to implement the authenticate() method of the sleigh, which takes the name of the person, who wants to board the sleigh .. 2023. 1. 4.
1209. Grasshopper - Combine strings Combine strings function Create a function named (combine_names) that accepts two parameters (first and last name). The function should return the full name. Example: combine_names('James', 'Stevens') returns: 'James Stevens' Solution: class Names: @staticmethod def combine(a, b): return " ".join([a, b]) combine_names = Names.combine 2022. 12. 9.
1111. Grasshopper - Debug sayHello Debugging sayHello function The starship Enterprise has run into some problem when creating a program to greet everyone as they come aboard. It is your job to fix the code and get the program working again! Example output: Hello, Mr. Spock Solution: class SayHello: def __init__(self): self.__hello = "Hello" def say(self, name): return f"{self.__hello}, {name}" say_hello = SayHello().say 2022. 11. 12.
1110. No oddities here Write a small function that returns the values of an array that are not odd. All values in the array will be integers. Return the good values in the order they are given. Solution: class NoOdd: def __init__(self): self.__values: list[int] = [] def run(self, values: list[int]) -> list[int]: self._set_values(values) self._remove_odd() return self._get_values() def _set_values(self, values) -> None.. 2022. 11. 10.