diff --git a/gb-python-ls2-1.py b/gb-python-ls2-1.py new file mode 100644 index 0000000..b0bd152 --- /dev/null +++ b/gb-python-ls2-1.py @@ -0,0 +1,4 @@ +a = list(input('Write something:) ')) +print(a) +for element in a: + print(type(element)) \ No newline at end of file diff --git a/gb-python-ls2-2.py b/gb-python-ls2-2.py new file mode 100644 index 0000000..027fa3c --- /dev/null +++ b/gb-python-ls2-2.py @@ -0,0 +1,7 @@ +a = list(input('Write something:) ').split()) +print(a) + +for i in range(1, len(a), 2): + a[i - 1], a[i] = a[i], a[i - 1] + +print(a) \ No newline at end of file diff --git a/gb-python-ls2-3.py b/gb-python-ls2-3.py new file mode 100644 index 0000000..f5d34ba --- /dev/null +++ b/gb-python-ls2-3.py @@ -0,0 +1,9 @@ +l_seasons = ['зима', 'зима', 'весна', 'весна', 'весна', 'лето', 'лето', 'лето', 'осень', 'осень', 'осень', 'зима'] +d_seasons = {1: 'зима', 2: 'зима', 3: 'весна', 4: 'весна', 5: 'весна', 6: 'лето', 7: 'лето', 8: 'лето', 9: 'осень', + 10: 'осень', 11: 'осень', 12: 'зима'} +month = int(input('Enter the month number: ')) +if month in d_seasons: + print(l_seasons[month - 1]) + print(d_seasons[month]) +elso: + print('Invalid value') diff --git a/gb-python-ls2-4.py b/gb-python-ls2-4.py new file mode 100644 index 0000000..86fee9e --- /dev/null +++ b/gb-python-ls2-4.py @@ -0,0 +1,4 @@ +a = input('Enter few words separated by a space: ').split() + +for i, word in enumerate(a,1): + print(f'{i} {word[:10]}') \ No newline at end of file diff --git a/gb-python-ls2-5.py b/gb-python-ls2-5.py new file mode 100644 index 0000000..292c793 --- /dev/null +++ b/gb-python-ls2-5.py @@ -0,0 +1,8 @@ +a = [1, 9, 9, 7, 2, 0, 0, 1] +new_num = int(input('Enter a new rating: ')) +i = 0 +for n in a: + if new_num <= n: + i += 1 +a.insert(i, new_num) +print(a) \ No newline at end of file diff --git a/gb-python-ls2-6.py b/gb-python-ls2-6.py new file mode 100644 index 0000000..54ea542 --- /dev/null +++ b/gb-python-ls2-6.py @@ -0,0 +1,19 @@ +i = 1 +products = [] +n = int(input('Enter the number of products: ')) +for _ in range(n): + name = input('Enter the product name: ') + price = input('Enter the product price: ') + quantity = input('Enter the product quantity: ') + measure = input('Enter the units of measurement: ') + products.append((i, {'name': name, 'price': price, 'quantity': quantity, 'units': measure})) + i += 1 +print(products) +products_dict = {'name': [], 'price': [], 'quantity': [], 'measure': []} +for product in products: + products_dict['name'].append(product[1]['name']) + products_dict['price'].append(product[1]['price']) + products_dict['quantity'].append(product[1]['quantity']) + if product[1]['units'] not in products_dict['units']: + products_dict['units'].append(product[1]['units']) +print(products_dict) \ No newline at end of file