diff --git a/Hometask4.py b/Hometask4.py new file mode 100644 index 0000000..ce61fa0 --- /dev/null +++ b/Hometask4.py @@ -0,0 +1,50 @@ +# Списки + +# 1. Робота із списками +numbers = [1, 2, 3, 4, 5] +numbers.append(10) +numbers.append(20) +numbers.remove(10) +print(numbers) # Output: [1, 2, 3, 4, 5, 20] + +# 2. Знаходження суми +numbers = [1, 2, 3, 4, 5] +sum_of_numbers = sum(numbers) +print(sum_of_numbers) # Output: 15 + +# 3. Подвійні значення +numbers = [1, 2, 3, 4, 5] +doubled_numbers = [x * 2 for x in numbers] +print(doubled_numbers) # Output: [2, 4, 6, 8, 10]# Кортежі + +# 1. Робота із кортежами +fruits = ("яблуко", "банан", "апельсин") +for fruit in fruits: + print(fruit) + +# 2. Об'єднання кортежів +tuple1 = (1, 2, 3) +tuple2 = (4, 5, 6) +combined_tuple = tuple1 + tuple2 +print(combined_tuple) # Output: (1, 2, 3, 4, 5, 6)# Словники + +# 1. Робота із словниками +athlete = { + "ім'я": "Ліонель Мессі", + "вік": 34, + "спорт": "футбол", + "команда": "Інтер Маямі", +} +for key, value in athlete.items(): + print(f"{key}: {value}") + +# 2. Оновлення словника +books = {"1984": 1949, "To Kill a Mockingbird": 1960} +books["The Great Gatsby"] = 1925 +print(books) + +# 3. Пошук значення +countries = {"Україна": "Київ", "Франція": "Париж", "Німеччина": "Берлін"} +country = "Україна" # Змінити для перевірки різних випадків +capital = countries.get(country, "Країна не знайдена") +print(capital) # Output: "Київ" diff --git a/main.py b/main.py index f7282f6..77c835a 100644 --- a/main.py +++ b/main.py @@ -1,37 +1,18 @@ -user_1 = { - "name": "Tom", - "age": 25, - "balance": 10000, - "currency": "USD", - "status": "true", -} -user_2 = { - "name": "John", - "age": 17, - "balance": 5000, - "currency": "EUR", - "status": "false", -} -user_3 = { - "name": "Karine", - "age": 30, - "balance": 100000, - "currency": "UAH", - "status": "true", -} +a = [1, 2, 3, 4, 5] +b = ["appl", "bann", "cherr"] -lis_of_currency = ["USD", "EUR", "UAH", "GBP"] +a.append(6) +b.append("tomatto") +print(a, b) -if user_1["name"] and user_1["age"] >= 18 and user_1["status"]: - if user_1["balance"] >= 10000 and user_1["currency"] in lis_of_currency: - print( - f"Welcome to our service! You can create your binance account, welcome {user_1['name']}!" - ) - elif user_1["balance"] >= 1000 and user_1["currency"] in lis_of_currency: - print("You needmore money to create an account") - else: - print("You can't create an account") -elif user_1["name"] == "": - print("Please, write your name in your account description") -elif user_1["age"] < 18: - print("You are too young") +a.insert(3, 7.4) +b.insert(3, "bottle") +print(a, b) + +a.remove(7.4) +b.remove("bottle") +print(a, b) + +last_elem_1 = a.pop() +last_elem_2 = b.pop() +print(last_elem_1, last_elem_2)