Математическое моделирование прикладных задач
2 вариант
Сухова Ангелина КТ-42-19
Лабораторная работа № 4
Задание 1
def integret():
lst1 = []
n = (input('Введите числа в строку'))
lst = n.split()
for i in range(len(lst)):
if int(lst[i]) > 0:
lst1.append(int(lst[i]))
if int(lst[i]) < 0:
lst1.append(int(lst[i])**2)
print(lst1)
integret()
Задание 2
N = int(input())
d = {i: [j for j in range(2,i) if i % j == 0 ] for i in range(1,N+1)}
print(d)
Задание 3
surname = []
name = []
most_count_surname = 0
most_count_name = 0
most_common_name = []
most_common_surname = []
name_list = []
surname_list = []
person_list = ['Иванов Иван Иванович','Петров Петр Петрович',
'Иванов Петр Иванович', 'Иванов Иван Петрович', 'Иванов Петр Петрович',
'Петров Иван Петрович','Петров Иван Иванович', 'Петров Петр Иванович',
'Иванов Алексей Сергеевич','Васильев Петр Игнатьевич','Мосолова Кристина Иванович']
for item in person_list:
person = item.split()
surname = person[0]
surname_list.append(surname)
name = person[1]
name_list.append(name)
for item in surname_list:
count = surname_list.count(item)
if count>=most_count_surname:
most_count_surname = count
most_common_surname.append(item)
for item in name_list:
count = name_list.count(item)
if count>=most_count_name:
most_count_name = count
most_common_name.append(item)
|
|
name = set(most_common_name)
surname = set(most_common_surname)
print('Имя: ', name,' Количество: ', most_count_name,'\nФамилия: ', surname,' Количество: ', most_count_surname)
Задание 4
#1
people = {'Bob Smith': 16,'Alice Taylor': 19,'Rolf Wilson':21,'Anna Miller': 17}
adult_names = [person.split()[0] for person in people if people[person] >= 18]
print(adult_names)
#2
people = {'Bob Smith': 16,'Alice Taylor': 19,'Rolf Wilson': 21,'Anna Miller': 17}
def adult_filter(age):
return people[age]>=18
adult = filter(adult_filter,people.keys())
adult_names = list(map(lambda x: x.split()[0],adult))
print(adult_names)
Задание 5
s = [1, 2, 3, 4, 5, 3, 3, 3]
print(max(a for a in s if s.count(a) == max(map(s.count, s))))
Задание 6
students_names = ['Иванов Иван Иванович','Петров Петр Петрович',
'Иванов Петр Иванович', 'Иванов Иван Петрович', 'Иванов Петр Петрович',
'Петров Иван Петрович','Петров Иван Иванович', 'Петров Петр Иванович',
'Иванов Алексей Сергеевич','Васильев Петр Игнатьевич','Мосолова Кристина Иванович']
students_groups = ['КТ-42-19','ИВТ-31-19','КТ-31-20','КТ-40-18','ИВТ-36-19','КТ-39-20',
'КТ-41-19','ИВТ-41-20','КТ-32-20','КТ-40-19']
student_score = [[2,4,5,3,3],[4,5,5,3,4],[4,5,4,4,5],[5,5,5,5,5],[3,3,3,4,5],
[4,3,3,2,4],[3,2,3,4,4],[5,5,4,5,5],[3,4,5,4,3],[2,3,4,5,4]]
student_info = [[0 for x in range(0)] for y in range(10)]
for x in range(10):
student_info[x].append(students_names[x])
student_info[x].append(students_groups[x])
student_info[x].append(sum(student_score[x])/len(student_score[x]))
print(student_info)
Задание 7
students_names = ['Иванов Иван Иванович','Петров Петр Петрович',
'Иванов Петр Иванович', 'Иванов Иван Петрович', 'Иванов Петр Петрович',
'Петров Иван Петрович','Петров Иван Иванович', 'Петров Петр Иванович',
'Иванов Алексей Сергеевич','Васильев Петр Игнатьевич','Мосолова Кристина Иванович']
students_groups = ['КТ-42-19','ИВТ-31-19','КТ-31-20','КТ-40-18','ИВТ-36-19','КТ-39-20',
'КТ-41-19','ИВТ-41-20','КТ-32-20','КТ-40-19']
student_score = [[2,4,5,3,3],[4,5,5,3,4],[4,5,4,4,5],[5,5,5,5,5],[3,3,3,4,5],
[4,3,3,2,4],[3,2,3,4,4],[5,5,4,5,5],[3,4,5,4,3],[2,3,4,5,4]]
|
|
students_losers=[]
for x in range(10):
for y in range(5):
if student_score[x][y]==2:
students_losers.append(students_names[x]+' '+students_groups[x])
print(students_losers)
Задание 8
students_names = ['Иванов Иван Иванович','Петров Петр Петрович',
'Иванов Петр Иванович', 'Иванов Иван Петрович', 'Иванов Петр Петрович',
'Петров Иван Петрович','Петров Иван Иванович', 'Петров Петр Иванович',
'Иванов Алексей Сергеевич','Васильев Петр Игнатьевич','Мосолова Кристина Иванович']
students_groups = ['КТ-42-19','ИВТ-31-19','КТ-31-20','КТ-40-18','ИВТ-36-19','КТ-39-20',
'КТ-41-19','ИВТ-41-20','КТ-32-20','КТ-40-19']
student_score = [[2,4,5,3,3],[4,5,5,3,4],[4,5,4,4,5],[5,5,5,5,5],[3,3,3,4,5],
[4,3,3,2,4],[3,2,3,4,4],[5,5,4,5,5],[3,4,5,4,3],[2,3,4,5,4]]
students_losers=[]
for x in range(10):
for y in range(5):
if student_score[x][y]==2:
full_name = students_names[x].split()
name = full_name[0] +' '+ full_name[1][0]+'.'+ full_name[2][0]+'.'
students_losers.append(name +' '+students_groups[x])
print(students_losers)
Задание 9
def mod_checker(x, mod=0):
return lambda y: y % x == mod
mod_3 = mod_checker(3)
print(mod_3(4))
mod_3_1 = mod_checker(3, 1)
print(mod_3_1(4))