-
Three New OOP Missions with Decorators, Bit Manipulation and Regex
Hello, checkiomates🐱👤!
Kontynuujemy tłumaczenie naszych misji początkowych! Tym razem wszystkie misje na dwóch pierwszych stacjach o łatwym poziomie trudności "Strings and Integers" oraz "List but not the least" - zostały przetłumaczone na język polski!
🏁 MISSIONS:
This week we prepared for you 3 new missions in the series about basic terms of Object Oriented Programming (OOP). We believe, this is not the end of the series, so if you have ideas of its continuing - please, share in series dedicated forum post.
OOP 5: Parent - Child by freeman_lex -
5.1. Create an ElectricCar class that inherits properties from the Car class.
5.2. Modify the __init__ method of the ElectricCar class so that it uses super() to call the __init__ method of the Car class.
5.3. Add a new attribute battery_capacity of type int to the ElectricCar class __init__ method. This attribute must be passing as argument. Put this argument before brand and model, because arguments without default values must go before ones that have.
5.4. Create a my_electric_car instance of the ElectricCar class, passing battery_capacity, brand, model with values 100, "Tesla", "Model 3" respectively.
OOP 6: Overriding Methods by freeman_lex -
6.1. Rewrite start_engine and stop_engine methods of the ElectricCar class to display another messages "Electric motor has started" and "Electric motor has stopped" respectively and change attributes the same way.
6.2. Call the start_engine method for the my_electric_car instance.
6.3. Create my_electric_car2 (values 60, "Toyota", "Prius"), start and stop its engine.
OOP 7: Adding Parameters by freeman_lex -
7.1. Add the fuel_used attribute inside __init__ method of Car class without changing its arguments and assign it a value of 0 liters.
7.2. Add the fuel_consumption attribute inside __init__ method of Car class, passing it as a method argument with default value of 7 (liters/100 km).
7.3. Add a drive method to the Car class that takes the distance argument of type int (km). If an instance of class had started - increment fuel_used with the proper value and display the message "Currently driven {distance} km, total fuel used - {fuel_used} l". If the instance had not started, display "Start the car before driving!".
7.4. Rewrite the method for the ElectricCar class, do not increment fuel_used (since electric car doesn't used fuel), change the successful message to "Currently driven {distance} km on electric motor", keep the unsuccessful message unchanged.
💡ARTICLES:
Todays articles are about effective using of Python decorators, bit manipulation and advanced regex patterns.
Understanding Python Decorators and How to Use Them Effectively - Python decorators enable us to extend the functionality of functions and methods elegantly, without altering their code. In my opinion, mastering decorators is a must for any Python programmer who wants to take their coding skills to the next level and contribute to more efficient and cleaner codebases.
The Power of Bit Manipulation - Let's smash some bits! - Bit manipulation is the act of algorithmically manipulating bits or other pieces of data shorter than a byte. Closely related to bit manipulation is bitwise operations. In bitwise operations, we perform operations on individual bits of a number. Bit manipulation is used in many algorithms and data structures where we need to store data in a compact space.
15 Examples for Text Processing using Regex - Regular expressions (regex) are a powerful tool for pattern matching and text processing in Python. While the basics of regex are well-known, there are advanced techniques and complex patterns that can take your text-processing skills to new heights. In this article, we will explore 15 complex examples of using regex in Python, demonstrating its versatility and effectiveness in solving various text-processing challenges.
A bit of humor at the end!
🙌 Thanks for your attention! Hope to meet you at CheckiO. We are really interested in your thoughts! Please, leave a comment below! ⤵
Welcome to CheckiO - games for coders where you can improve your codings skills.
The main idea behind these games is to give you the opportunity to learn by exchanging experience with the rest of the community. Every day we are trying to find interesting solutions for you to help you become a better coder.
Join the Game