SharedPython.ipynbOpen in CoCalc

45 >> 3
5
a = u'хуй'

'{0},{0}'.format(a)
'хуй,хуй'


#Num 1
import random
import time
N = input('Введи число больше 50  ₍ ᕕ(´◓⌓◔)ᕗ⁾')
mas = [random.randint(0, 1000) for i in range(int(N))]
print(mas)
print([x**2 for x in mas])
print(':'.join(str(i) for i in mas[2::2]))
print([i for i in mas[::-1] if i%2 == 0])
List = ['Komissarov A.S.','Ft-260015', time.asctime(time.localtime()), ' '.join([str(i) for i in mas[::-1] if i%3 == 0]), ', '.join([str(i) for i in mas[::-1] if i%5 == 0])]
f = open('text.txt', 'w')
f.writelines([i + '\n' for i in List])
f.close()
Введи число больше 50 ₍ ᕕ(´◓⌓◔)ᕗ⁾
[459, 666, 831, 660, 177, 36, 514, 208, 641, 37, 860, 696, 425, 550, 479, 148, 180, 536, 228, 454] [210681, 443556, 690561, 435600, 31329, 1296, 264196, 43264, 410881, 1369, 739600, 484416, 180625, 302500, 229441, 21904, 32400, 287296, 51984, 206116] 831:177:514:641:860:425:479:180:228 [454, 228, 536, 180, 148, 550, 696, 860, 208, 514, 36, 660, 666]
#Num 2
import random
N = [random.randint(-10,10) for i in range(4)]
print(N)
mx = N[0]
for i in range(len(N)):
    if N[i] > mx:
        mx = N[i]
        imx = i
mn = N[0]
for i in range(len(N)):
    if N[i] < mn:
        mn = N[i]
        imn = i
print('min=', mn,'№' ,imn , '\n', 'max=' ,mx, '№', imx, '\n', end=' ')
K = [x for x in N if x > 0]
print('тут',sum(K)/len(K))
print(sum([i for i in N if (i < 0 and i%2 == 1)]))
for i in range(len(N)):
    if N[i] == mn:
        N[i] = mx
        continue
    if N[i] == mx:
        N[i] = mn
print(N)
[3, 5, 9, -7] min= -7 № 3 max= 9 № 2 тут 5.666666666666667 -7 [3, 5, -7, 9]
Np = sum([x for x in N if x > 0]) # <- вот это
np = [x for x in N if x > 0]
print(N, '\n', np)
[2, 8, 8, 9, -2, -9, 7, -4, 2, -4, 0, -5, 3, -9, 2, 4, 4, 9, -5, -9, -7, 10, 8, -8, 3, 1, 2, 2, -7, -8] [2, 8, 8, 9, 7, 2, 3, 2, 4, 4, 9, 10, 8, 3, 1, 2, 2]
#Num 3

from math import *
def num3(a=0, b=1, h=0.1, func='sin(x**2)'):
    print('a=', a, '\n', 'b=', b, '\n', 'h=', h, '\n', '\n', 'f(x)=', func, sep='',end='\n')
    for x in [x*0.1 for x in range(a,b*11)]:
        print(x, '\t', 'f(x)=', str(eval(func)), '\n', sep='',end='\n')
    
num3()
a=0 b=1 h=0.1 f(x)=sin(x**2) 0.0 f(x)=0.0 0.1 f(x)=0.009999833334166666 0.2 f(x)=0.03998933418663417 0.30000000000000004 f(x)=0.08987854919801107 0.4 f(x)=0.159318206614246 0.5 f(x)=0.24740395925452294 0.6000000000000001 f(x)=0.35227423327509005 0.7000000000000001 f(x)=0.47062588817115814 0.8 f(x)=0.5971954413623921 0.9 f(x)=0.7242871743701426 1.0 f(x)=0.8414709848078965
#Num 4
Mat = lambda x: [[random.randint(-5, 5) for i in range(x)] for j in range(x)] 
M = Mat(5);M
[[-4, 5, -5, 1, -1], [-2, 1, -5, 4, 4], [5, 3, 4, -4, 5], [5, 5, -3, -1, 2], [-1, -5, 3, 3, -4]]
sM = sum([M[i][i] for i in range(len(M[0]))]);sM
-4
sr = [sum(M[i])/len(M[i]) for i in range(len(M[0]))];sr
[-0.8, 0.4, 2.6, 1.6, -0.8]
mx = sr[0]
for i in range(len(sr)):
    if sr[i] > mx:
        mx = sr[i]
print(mx)
2.6
A = Mat(5)
for i in range(len(M[0])):
    for j in range(len(M[0])):
        A[i][j] = M[j][i]
A
[[-4, -2, 5, 5, -1], [5, 1, 3, 5, -5], [-5, -5, 4, -3, 3], [1, 4, -4, -1, 3], [-1, 4, 5, 2, -4]]
aA = [[abs(A[i][j]) for j in range(len(A[0]))] for i in range(len(A[0]))]
aA
[[4, 2, 5, 5, 1], [5, 1, 3, 5, 5], [5, 5, 4, 3, 3], [1, 4, 4, 1, 3], [1, 4, 5, 2, 4]]
abm = [sum(i) for i in aA] 
abm
[17, 19, 20, 13, 16]
mx = abm[0]
for i in range(len(abm)):
    if abm[i] > mx:
        mx = abm[i]
        imx = i
print(mx,imx)
20 2
mx = A[imx][0]
for i in range(len(A[imx])):
    if A[imx][i] > mx:
        mx = A[imx][i]
print(mx)
4
#Num 5
import random
import math
imx = 0
Nor = [(random.randint(-20,20),random.randint(-20,20)) for i in range(10)]
Nor
[(-4, 8), (-14, -19), (12, 20), (19, -4), (-6, 19), (4, -3), (-6, 1), (-8, -1), (-6, 19), (18, 7)]
def norm(lis):
    return [math.sqrt(lis[i][0]**2 + lis[i][1]**2) for i in range(len(lis))]
nr = norm(Nor);nr
[0.223606797749979, 23.600847442411894, 23.323807579381203, 19.4164878389476, 19.924858845171276, 5.0, 6.082762530298219, 8.06225774829855, 19.924858845171276, 19.313207915827967]
mx = nr[0]
for i in range(len(nr)):
    if nr[i] <  mx:
        mx = nr[i]
        imx = i
print(mx,imx)
0.223606797749979 2
print('значение',mx,'\n','номер',imx)
значение 0.223606797749979 номер 0
Nor[0] = (0.1, 0.2)
Nor
[(0.1, 0.2), (-14, -19), (12, 20), (19, -4), (-6, 19), (4, -3), (-6, 1), (-8, -1), (-6, 19), (18, 7)]