TobiaszFuczek / Fuel-Consumption

0 stars 0 forks source link

Fuel Consumption #1

Open TobiaszFuczek opened 1 year ago

TobiaszFuczek commented 1 year ago

DoD ✅

Description ✉️ - practice

User Stories 📖

Prepare the fuel consumption` app according to the following user stories:

The app should not save the data in the DB, it's allowed to store the data in the memory. Please prepare the written technical desing the app, which would contain the following elements:

Please be creative, and try to propose nice solution which would satisfy our Client's needs 🚀 🧠

Scope 📦

Use Case: Image

Description ✉️ - theory

Interview questions ❓

Please, be prepared for the following questions: 1, 2, 3 (please prepare practical example - code snippet in the task description), 4, 5, 6,7, 8, 9, 10, 11 (please prepare practical example - code snippet in the task description), 12, 15, 16, 18 (please prepare practical example - code snippet in the task description), 20:

List of Questions

[JR: Whare are the answers with the code snippents?]

Data structure in practice 🏳

Data Structures v1 Data Structures v2

[JR: Whare are the answers with the code snippents?]

Good luck 🤞 .

All of the processes related to the GIT/Task workflow must be performed.

TobiaszFuczek commented 1 year ago

Ad. Interview questions:

  1. Python Benefits 1.1. Objects, Modules

    def(self, car_make, years_of_production):
        self.car_make = car_make
        self.years_of_production = years_of_production
    
    def your_name(self):
        return f"I am car make {self.car_make}, years of production: {self.years_of_production}"

    1.2. Exeptions

    try:
        result = a / b
        return result
    except ZeroDivisionError:
        print("Błąd: Dzielenie przez zero!")
        return None
    except TypeError:
        print("Błąd: Nieprawidłowy typ danych!")
        return None

1.3. Automatic Memory Management

 #Tworzenie listy zawierającej milion liczb od 0 do 999999
my_list = list(range(1000000))

 #Przykład użycia obiektów z listy
sum_of_numbers = sum(my_list)
average = sum_of_numbers / len(my_list)

print("Średnia liczb:", average)

1.4 Python is a open-source language because is open for all . His access is open for free for all and his open-source is available access public and can be modificate.

2.PEP 8

Standard library imports. Related third party imports. Local application/library specific imports.

def factorial(n):

    'Oblicza silnię liczby n.

    Silnia liczby n jest iloczynem wszystkich liczb całkowitych od 1 do n.

    Argumenty:
    n (int): Liczba, dla której obliczana jest silnia.

    Zwracane wartości:
    int: Silnia liczby n.
    '
    if n == 0:
        return 1
    else:
        result = 1
        for i in range(1, n + 1):
            result *= i
        return result

# Wywołanie funkcji i wyświetlenie docstringu
print("Docstring dla funkcji factorial:")
print(factorial.__doc__)

# Obliczenie i wyświetlenie silnii dla liczby 5
print("Silnia liczby 5 to:", factorial(5))

data = [1, 2, 3, 4, 5]

Pickling (zapis obiektu do pliku)

with open('data.pickle', 'wb') as file: pickle.dump(data, file)```

import pickle

Unpickling (odczyt obiektu z pliku)

with open('data.pickle', 'rb') as file: loaded_data = pickle.load(file)

print(loaded_data) # Wyświetli: [1, 2, 3, 4, 5]


4.Python language is  interpreted language, what that is mean, source code is a procesing and executing immediately for the interpreter.
5.Memory manage in Python
`
x = [1, 2, 3]  
y = x          
x = None       
`
 Create List
 assigning a reference to the same list
 reference None to the variable x, wchich cut to the reference to the list
TobiaszFuczek commented 1 year ago
  1. What are the tools that help to find bugs or perform the static analysis.

num = 5 print("Kwadrat liczby", num, "to", calculate_square(num))


3.We can generate pylint in terminal give name the file: pylint example.py
-pychecker currently is not using in programming world
TobiaszFuczek commented 1 year ago

7.Decorators

    def wrapper():
        print("Something is happening before the function is called.")
        func()
        print("Something is happening after the function is called.")
    return wrapper

@my_decorator
def say_hello():
    print("Hello!")

say_hello()

This example we have a function my_decorator() who take function func() as argument and return function inside wrapper(). Then apply this dekorator to function say_hello() with @my_decorator.

TobiaszFuczek commented 1 year ago

8.Different lists and tuple

my_tuple = (1, 2, 3)
my_list = [4, 5, 6]

my_dict = {
    my_tuple: "To jest krotka",
    my_list: "To jest lista"
}

tuple_key = (1, 2, 3)
print(my_dict[tuple_key])

list_key = [4, 5, 6]
print(my_dict[list_key])

Tuple can use in dictionary, the tuple is immutable bat lists are mutable, what allow in changing value in list.

TobiaszFuczek commented 1 year ago

10.Dict and Lists comprehensions

words = ["Apple", "Banana", "Cherry"]
lowercase_words = [word.lower() for word in words]
print(lowercase_words)  # Wyświetli: ['apple', 'banana', 'cherry']

fruits = ["apple", "banana", "cherry", "date"]
lengths_dict = {fruit: len(fruit) for fruit in fruits}
print(lengths_dict)  # Wyświetli: {'apple': 5, 'banana': 6, 'cherry': 6, 'date': 4}

Example 1: Create new list with using list words[]. Example 2: Crate dictionary with using list fruits[]

TobiaszFuczek commented 1 year ago
  1. Python provides two built-in types: 1) Mutable and 2) Immutable.

Mutable built-in types are:

List Sets Dictionaries Immutable built-in types Strings Tuples Numbers Immutable built-in types are:

Strings Tuples Numbers

TobiaszFuczek commented 1 year ago

15.Pass- in following example pass is as empty function but the code will perform in correct.

def empty_function():
    pass
TobiaszFuczek commented 1 year ago
  1. Iterators- it object wchich enables iterations (passing) for collections or data sequences as well as tuples, dictionary, files.
my_list = [1, 2, 3, 4, 5]
my_iterator = iter(my_list)

print(next(my_iterator))
TobiaszFuczek commented 1 year ago
  1. Slicing- is tools/technic who allow in selected specified snippets by defining the scope indexes.
my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
sublist = my_list[2:5]
print(sublist)
TobiaszFuczek commented 1 year ago
  1. Docstring is description useable in specified function, the example is following:
def calculate_square(x):
    """
    Calculate the square of a number.

    Args:
        x (int or float): The input number.

    Returns:
        int or float: The square of the input number.
    """
    return x ** 2

print(calculate_square.__doc__)