Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
list = [1, 2.0, True, 'Hello', None, ['1', 2, 3.0], (1, 2, 3), {'name': 'Tom', 'second_name': 'Hardy'}, complex(2, 3), set(['a', 'b', 'c', 'b', 'a'])]
for item in list:
print(type(item))
18 changes: 18 additions & 0 deletions task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Для списка реализовать обмен значений соседних элементов
list_length = input('Введите длинну списка - ')
if not list_length.isdigit() or int(list_length) <= 0: # проверяем ввод длины списка
print('Длинна - это положительное, целое число')
exit()
list_length = int(list_length)
ind = 0
list = []
while ind < list_length:
list.insert(ind, input('Введите элемент ' + str(ind) + ' - '))
ind += 1
print(list) # выводим введенный список
index = 0
for item in list:
if index % 2 == 1:
list[index], list[index-1] = list[index-1], list[index]
index += 1
print(list) # выводим измененный список
68 changes: 68 additions & 0 deletions task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Пользователь вводит месяц в виде целого числа от 1 до 12.
# Сообщить к какому времени года относится месяц (зима, весна, лето, осень). Напишите решения через list и через dict.
month = input('Введите месяц - ')
if not month.isdigit() or int(month) <= 0 or int(month) < 1 or int(month) > 12: # проверяем ввод месяца
print('Месяц - это положительное целое число, от 1 до 12')
exit()
month = int(month)
monthes = ['Зима', 'Зима', 'Весна', 'Весна', 'Весна', 'Лето', 'Лето', 'Лето', 'Осень', 'Осень', 'Осень', 'Зима']
print(monthes[month-1]) # через список

dict_seasons = {
1: 'Весна',
2: 'Лето',
3: 'Осень',
4: 'Зима'
}
dict_monthes = {
1: {
'name': 'Январь',
'season': 4
},
2: {
'name': 'Февраль',
'season': 4
},
3: {
'name': 'Март',
'season': 1
},
4: {
'name': 'Апрель',
'season': 1
},
5: {
'name': 'Май',
'season': 1
},
6: {
'name': 'Июнь',
'season': 2
},
7: {
'name': 'Июль',
'season': 2
},
8: {
'name': 'Август',
'season': 2
},
9: {
'name': 'Сентябрь',
'season': 3
},
10: {
'name': 'Октябрь',
'season': 3
},
11: {
'name': 'Ноябрь',
'season': 3
},
12: {
'name': 'Декабрь',
'season': 4
}
}
dict_month = dict_monthes.get(month)
print('Месяц ' + dict_month['name'] + '. Время года - ' + dict_seasons[dict_month['season']] + '!') # через словарь
6 changes: 6 additions & 0 deletions task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Пользователь вводит строку из нескольких слов, разделённых пробелами. Вывести каждое слово с новой строки.
# Строки необходимо пронумеровать. Если в слово длинное, выводить только первые 10 букв в слове
long_string = input('Введите сроку: ')
list_words = long_string.split()
for ind, word in enumerate(list_words, 1):
print(ind, word[:9])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему 9) последний не включается же

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поспешил, запустил код с :10, и показалось не правильно вывелось. Вообщем недо-тест.

11 changes: 11 additions & 0 deletions task5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Реализовать структуру «Рейтинг», представляющую собой не возрастающий набор натуральных чисел.
rating = [9, 5, 2, 1]
while True: # Запрашиваем новые элементы, пока программа не будет остановлена
new_element = input('Введите новый элемент рейтинга - ')
if not new_element.isdigit() or int(new_element) < 1: # проверяем, что число натуральное
print('Введенное значение должно быть натуральным числом!')
continue
new_element = int(new_element)
rating.append(new_element) # добавляем новый элемент в конец рейтинга
rating.sort() # Сортируем рейтинг
print(rating)
28 changes: 28 additions & 0 deletions task6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Реализовать структуру данных «Товары».
products = []
product_params = {'name': 'Название', 'price': 'цена', 'count': 'Количество', 'ed': 'ед'}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хорошая идея сделать отдельно названия для вывода

ind = 0
while True:
print('Введите товар', str(ind+1))
current_params = {}
for param in product_params.keys():
new_value = input(product_params[param] + ': ')
if new_value.isdigit() :
new_value = int(new_value)
current_params[param] = new_value
products.append((ind, current_params))
if input('"0" для завершения ввода: ') == '0':
break
ind += 1
print('Вы ввели: ')
print(products)
result = {}
for param in product_params:
result[param] = set([])
for product in products:
for param in product_params:
result[param].add(product[1][param])
for param in product_params:
result[param] = list(result[param])
print('Аналитика:')
print(result)