- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstHomework.py
More file actions
Latest commit
114 lines (99 loc) · 2.72 KB
/
Copy pathFirstHomework.py
File metadata and controls
114 lines (99 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
deffirst_task():
n=int(input("Enter value to first task"))
counter=0
i=0
whileTrue:
forjinrange(i):
print(i)
counter=counter+1
ifcounter==n:
break
ifcounter==n:
break
i=i+1
defsecond_task():
inp=input("Enter the list of values to second task")
x=int(input("Enter value to second task"))
lst=map(int, inp.split())
lst=list(lst)
flag=False
foriinrange(len(lst)):
iflst[i] ==x:
print(i)
flag=True
ifnotflag:
print("Отсутствует")
defthird_task():
print("Enter values to third task")
mx= []
inp=0
whileTrue:
inp=input()
ifinp=="end":
break
lst=map(int, inp.split())
mx.append(list(lst))
print(mx)
new_mx= []
tmp_lst= []
foriinrange(len(mx)):
tmp_lst.clear()
forjinrange(len(mx[i])):
ifi>0:
up=mx[i-1][j]
else:
up=mx[len(mx) -1][j]
ifi<len(mx) -1:
down=mx[i+1][j]
else:
down=mx[0][j]
ifj>0:
left=mx[i][j-1]
else:
left=mx[i][len(mx[i]) -1]
ifj<len(mx[i]) -1:
right=mx[i][j+1]
else:
right=mx[i][0]
tmp_lst.append(up+down+left+right)
new_mx.append(tmp_lst.copy())
print(new_mx)
deffourth_task():
n=int(input("Enter value to fourth task"))
ifn<0:
print("Your number is negative, try again next time")
return
num=0
tmp= []
res_mx= []
foriinrange(n):
tmp.clear()
forjinrange(n):
tmp.append(0)
res_mx.append(tmp.copy())
l=int(n/2)
counter=0
forturnsinrange(l):
forrowinrange(0+turns, n-turns, 1):
counter=counter+1
res_mx[turns][row] =counter
forcolinrange(0+turns+1, n-turns, 1):
counter=counter+1
res_mx[col][n-1-turns] =counter
forrow_linrange(n-2-turns, turns-1, -1):
counter=counter+1
res_mx[n-1-turns][row_l] =counter
forcol_linrange(n-2-turns, turns, -1):
counter=counter+1
res_mx[col_l][turns] =counter
ifn%2==1:
res_mx[l][l] =n**2
foriinrange(len(res_mx)):
print(res_mx[i], "\n")
defmain():
first_task()
second_task()
third_task()
fourth_task()
if__name__=="__main__":
main()