diff --git a/TEMA4/gct.md b/TEMA4/gct.md index 701a229..fae5a2b 100644 --- a/TEMA4/gct.md +++ b/TEMA4/gct.md @@ -6,8 +6,9 @@ _Код:_ ```py import cmath -a = tuple([((round(cmath.phase(0.2+0.8j),2)) * 20)// 3] + [((round(cmath.phase(0.2+0.8j),2)) * 20) % 3]) -print(a) +n = ((round(cmath.phase(0.2+0.8j),2)) * 20) +a, b = divmod(n, 3) +print(a,b) ``` _Вывод:_ @@ -28,7 +29,7 @@ start_time = time.time() _Вывод:_ ```py -16:26 +12:5 ``` ## 3. @@ -38,19 +39,13 @@ _Код:_ ```py import random spis = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'] -i = 0 -l = [] -while i != 3: - a = random.choice(spis) - if a not in l: - l.append(a) - i += 1 +l = random.sample(spis, 3) print(l) ``` _Вывод:_ ```py -['Четверг', 'Воскресенье', 'Суббота'] +['Понедельник', 'Суббота', 'Вторник'] ``` ## 4. @@ -59,7 +54,9 @@ _Вывод:_ _Код:_ ```py import random -print(random.randrange(14,32,3)) +num = list(range(14, 32, 3)) +res = random.choice(num) +print(res) ``` _Вывод:_ @@ -73,17 +70,10 @@ _Вывод:_ _Код:_ ```py import random -N = round((random.gauss(15, 4))) -l = [] -c = [] -k = 0 -for i in range(65, 91): # ASCII коды от A (65) до Z (90) - l.append(chr(i)) -while k != N: - r = random.choice(l) - if r not in c: - c.append(r) - k += 1 +import string +N = round(random.gauss(15, 4)) +l = string.ascii_uppercase +c = random.sample(l, N) print(c) print(N) print(f'Длина массива: {len(c)}') @@ -91,9 +81,9 @@ print(f'Длина массива: {len(c)}') _Вывод:_ ```py -['I', 'Q', 'N', 'O', 'H', 'C', 'K', 'R', 'B', 'G', 'J', 'Y', 'V', 'S'] -14 -Длина массива: 14 +['M', 'Z', 'V', 'Q', 'G', 'O', 'N', 'J', 'X', 'R', 'C', 'S', 'H', 'B', 'T', 'F', 'U', 'E', 'K', 'W'] +20 +Длина массива: 20 ``` ## 6. diff --git a/TEMA4/genct4.py b/TEMA4/genct4.py index 365716b..e0c8950 100644 --- a/TEMA4/genct4.py +++ b/TEMA4/genct4.py @@ -3,8 +3,9 @@ ## 1. import cmath -a = tuple([((round(cmath.phase(0.2+0.8j),2)) * 20)// 3] + [((round(cmath.phase(0.2+0.8j),2)) * 20) % 3]) -print(a) +n = ((round(cmath.phase(0.2+0.8j),2)) * 20) +a, b = divmod(n, 3) +print(a,b) ## 2. import time @@ -15,32 +16,21 @@ start_time = time.time() ## 3. import random spis = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'] -i = 0 -l = [] -while i != 3: - a = random.choice(spis) - if a not in l: - l.append(a) - i += 1 +l = random.sample(spis, 3) print(l) ## 4. import random -print(random.randrange(14,32,3)) +num = list(range(14, 32, 3)) +res = random.choice(num) +print(res) ## 5. import random -N = round((random.gauss(15, 4))) -l = [] -c = [] -k = 0 -for i in range(65, 91): # ASCII коды от A (65) до Z (90) - l.append(chr(i)) -while k != N: - r = random.choice(l) - if r not in c: - c.append(r) - k += 1 +import string +N = round(random.gauss(15, 4)) +l = string.ascii_uppercase +c = random.sample(l, N) print(c) print(N) print(f'Длина массива: {len(c)}')