Орієнтовні розв'язки практичної роботи №4 тренінгу Python
Всі розв'язки по 100 балів
А
n = int(input())
l = list(map(int,input().split()))
message = 'Yes'
min = l[0]
for i in range(1,n):
if l[i] <= min:
message = 'No'
break
min = l[i]
print(message)
B
n = int(input()) #кільк. чисел
s1 = 0 #кільк додатніх
s2 = 0 #кільк від'ємних
for i in range(n):
a = int(input())
if a > 0:
s1 += 1
if a < 0:
s2 += 1
print(s1, s2, n - s1 - s2)
C
n = int(input()) #кільк. елементів
l = list(map(int,input().split())) #введ. списку в один рядок
message = 'NO' #поч знач результату
for i in range(1,n):
if l[i] * l[i - 1] > 0: #якщо наступний і попередній мають однакові знаки
message = 'YES'
break
print(message)
D
n = int(input())
numbers = list(range(2, n + 1))
for number in numbers:
if number != 0:
for candidate in range(2 * number, n+1, number):
numbers[candidate-2] = 0
print(list(filter(lambda x: x != 0, numbers)))
E
from statistics import *
n = int(input())
l = [int(s) for s in input().split()]
sr_l = mean(l)
s=0
l2=[]
for a in l:
if a > sr_l:
s+=1
l2.append(a)
print(s)
print(*l2)
F
l = [int(s) for s in input().split()]
l2=[]
for i in range(len(l)):
if len(l) == 1:
l2.append(l[i])
break
if i == 0:
l2.append(l[i+1]+l[-1])
if i == len(l) - 1:
l2.append(l[i-1]+l[0])
if i > 0 and i < (len(l) - 1):
l2.append(l[i+1]+l[i-1])
print(*l2)
G
a = [int(s) for s in input().split()]
a_set = set(a)
most_common = None
qty_most_common = 0
for item in a_set:
qty = a.count(item)
if qty > qty_most_common:
qty_most_common = qty
most_common = item
print(most_common)
H
a = [int(s) for s in input().split()]
a_set = set(a)
l=[]
for item in a_set:
qty = a.count(item)
if qty > 1:
l.append(item)
print(*l)
I
n, m = map(int, input().split())
s = 0
a = []
for i in range(n):
a.append([int(j) for j in input().split()])
for i in range(len(a)):
for j in range(len(a[i])):
if i>0 and j>0 and i<n-1 and j<m-1:
s += a[i][j]
print(s)
J
n = int(input())
l = [int(s) for s in input().split()]
l2 = []
for a in l:
if a%2 == 0:
l2.append(a)
for a in l:
if a%2 != 0:
l2.append(a)
print(*l2)
Задачі:
http://dn.hoippo.km.ua/python/index.html
Немає коментарів:
Дописати коментар