форкнуто от main/python-labs
Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
210 строки
4.4 KiB
Python
210 строки
4.4 KiB
Python
# ТЕМА 4 "Зеленкина Ксения Михайловна"
|
|
# 2.1
|
|
print(round(123.456,1))
|
|
print(round(123.456,0))
|
|
|
|
print(round(123.456))
|
|
|
|
# 2.2.
|
|
gg=range(76,123,9)
|
|
print(gg)
|
|
|
|
print(list(gg))
|
|
|
|
print(list(range(23)))
|
|
|
|
# 2.3.
|
|
qq = ['Зеленкина', 'Криви', 'Цветкова', 'Капитонов']
|
|
print(qq)
|
|
ff = zip(gg, qq)
|
|
print(ff)
|
|
|
|
result_tuple = tuple(ff)
|
|
print(result_tuple)
|
|
print(result_tuple[0])
|
|
print(result_tuple[2])
|
|
|
|
# 2.4.
|
|
#fff=float(input('коэффициент усиления=')); dan=eval('5*fff-156')
|
|
#print(fff, dan)
|
|
|
|
# 2.5
|
|
#exec(input('введите инструкции:'))
|
|
|
|
# 2.6
|
|
print(abs(-7.5))
|
|
print(pow(3, 4))
|
|
|
|
numbers = [5, 2, 8, 1]
|
|
print(max(numbers))
|
|
print(min(numbers))
|
|
|
|
print(sum(numbers))
|
|
|
|
a, b = divmod(17, 5)
|
|
print(a, b)
|
|
|
|
text = "Hello"
|
|
print(len(text))
|
|
|
|
numbers = [1, 2, 3, 4]
|
|
text_numbers = list(map(str, numbers))
|
|
print(text_numbers)
|
|
|
|
#3
|
|
import math
|
|
print(dir(math))
|
|
help(math.factorial)
|
|
print(math.factorial(5))
|
|
|
|
import math
|
|
|
|
print(dir(math))
|
|
help(math.factorial)
|
|
|
|
print(math.factorial(5))
|
|
print(math.sin(math.pi/2))
|
|
print(math.acos(0.5))
|
|
print(math.degrees(math.pi))
|
|
print(math.radians(180))
|
|
print(math.exp(1))
|
|
print(math.log(100))
|
|
print(math.log10(100))
|
|
print(math.sqrt(25))
|
|
print(math.ceil(4.2))
|
|
print(math.floor(4.9))
|
|
print(math.pi)
|
|
|
|
result = math.sin(2 * math.pi / 7 + math.exp(0.23))
|
|
print(result)
|
|
|
|
#4
|
|
import cmath
|
|
print(dir(cmath))
|
|
print(cmath.sqrt(1.2-0.5j))
|
|
print(cmath.phase(1-0.5j))
|
|
|
|
#5
|
|
import random
|
|
print(dir(random))
|
|
help(random.seed)
|
|
print(random.seed())
|
|
|
|
import random
|
|
|
|
random.seed(42)
|
|
|
|
print(random.random())
|
|
print(random.uniform(10, 20))
|
|
print(random.randint(1, 6))
|
|
print(random.gauss(0, 1))
|
|
|
|
fruits = ["яблоко", "банан", "апельсин", "киви"]
|
|
print(random.choice(fruits))
|
|
|
|
cards = ["Туз", "Король", "Дама", "Валет"]
|
|
random.shuffle(cards)
|
|
print(cards)
|
|
|
|
numbers = list(range(1, 51))
|
|
print(random.sample(numbers, 5))
|
|
|
|
print(random.betavariate(2, 5))
|
|
print(random.gammavariate(2, 1))
|
|
print(random.randint(100, 999))
|
|
print(random.uniform(-5, 5))
|
|
|
|
random_values = [random.uniform(0, 1), random.gauss(0, 1), random.betavariate(2, 5), random.gammavariate(2, 1)]
|
|
print(random_values)
|
|
|
|
#6
|
|
import time
|
|
print(dir(time))
|
|
c1=time.time()
|
|
print(c1)
|
|
c2=time.time()-c1
|
|
print(c2)
|
|
dat=time.gmtime()
|
|
print(dat)
|
|
print(dat.tm_mon)
|
|
|
|
# local()
|
|
local_time = time.localtime()
|
|
print(local_time.tm_year)
|
|
print(local_time.tm_mon)
|
|
print(local_time.tm_mday)
|
|
print(local_time.tm_hour)
|
|
print(local_time.tm_min)
|
|
print(local_time.tm_sec)
|
|
|
|
# asctim()
|
|
time_str = time.asctime(local_time)
|
|
print(time_str)
|
|
|
|
#ctime()
|
|
current_seconds = time.time()
|
|
print(current_seconds)
|
|
time_from_seconds = time.ctime(current_seconds)
|
|
print(time_from_seconds)
|
|
|
|
#sleep()
|
|
print("Начинаем отсчет...")
|
|
for i in range(3, 0, -1):
|
|
print(f"{i}...")
|
|
time.sleep(1)
|
|
print("Запуск!")
|
|
|
|
#mtime
|
|
seconds_from_struct = time.mktime(local_time)
|
|
print(seconds_from_struct)
|
|
|
|
#Обратное преобразование из секунды
|
|
print(time.localtime(c1))
|
|
|
|
# Графические функции.
|
|
import pylab
|
|
x=list(range(-3,55,4))
|
|
t=list(range(15))
|
|
pylab.plot(t, x) # Создание графика в оперативной памяти
|
|
pylab.title('Первый график')
|
|
pylab.xlabel('время')
|
|
pylab.ylabel('сигнал')
|
|
pylab.show() # Отображение графика на экране
|
|
|
|
X1=[12,6,8,10,7]
|
|
X2=[5,7,9,11,13]
|
|
pylab.plot(X1)
|
|
pylab.plot(X2)
|
|
pylab.show()
|
|
|
|
region=['Центр','Урал','Сибирь','Юг']
|
|
naselen=[65,12,23,17]
|
|
pylab.pie(naselen,labels=region)
|
|
pylab.show()
|
|
|
|
#hist
|
|
import matplotlib.pyplot as plt
|
|
assessments = [3, 4, 5, 3, 4, 5, 5, 4, 3, 2, 4, 5, 3, 4, 5, 4, 3, 5, 4, 3]
|
|
plt.hist(assessments, bins=5, color='lightblue', edgecolor='black')
|
|
plt.xlabel('Оценки')
|
|
plt.ylabel('Количество студентов')
|
|
plt.title('Распределение оценок студентов')
|
|
plt.show()
|
|
|
|
#bar
|
|
fruits = ['Яблоки', 'Бананы', 'Апельсины', 'Груши']
|
|
count = [25, 30, 15, 20]
|
|
color = ['red', 'yellow', 'orange', 'green']
|
|
plt.bar(fruits, count, color=color)
|
|
plt.ylabel('Количество')
|
|
plt.title('Любимые фрукты')
|
|
plt.show()
|
|
|
|
#Statistic
|
|
import statistics
|
|
print(dir(statistics))
|
|
data = [1, 2, 3, 4, 5, 5, 6]
|
|
print("Mean:", statistics.mean(data))
|
|
print("Median:", statistics.median(data))
|
|
print("Mode:", statistics.mode(data))
|
|
print("Stdev:", statistics.stdev(data)) |