Solovyova_ED 2 недель назад
Родитель d986456727
Сommit 0f10c748af

@ -1 +1,384 @@
Тема 4 Соловьёва Е. Д.
os import
SyntaxError: invalid syntax
import os
os.chdir('C:\\Users\\Ekaterina\\OneDrive\\Desktop\\Solovyova\\python-labs\\TEMA4')
help('round')
Help on built-in function round in module builtins:
round(number, ndigits=None)
Round a number to a given precision in decimal digits.
The return value is an integer if ndigits is omitted or None. Otherwise
the return value has the same type as the number. ndigits may be negative.
round(123.456,1)
123.5
round(123.456,0)
123.0
type(123.5)
<class 'float'>
type(123.0)
<class 'float'>
s=round(123.456,1)
ss=type(123.5)
ss=round(123.456,0)
type(ss)
<class 'float'>
type(s)
<class 'float'>
round(123.456)
123
type(123)
<class 'int'>
gg=range(76,123,9)
пп
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
пп
NameError: name 'пп' is not defined
gg
range(76, 123, 9)
list(gg)
[76, 85, 94, 103, 112, 121]
range(23)
range(0, 23)
list(range(23))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
qq='Solovyova'
gg='Ivanov','Lazarev','Likova'
ff=zip(gg,qq)
ff
<zip object at 0x000001308EED4840>
tuple(ff)
(('Ivanov', 'S'), ('Lazarev', 'o'), ('Likova', 'l'))
gg=range(76,123,9)
list(gg)
[76, 85, 94, 103, 112, 121]
qq = ["Соловьёва", "Лыкова", "Филиппова", "Мельников"]
ff=zip(gg,qq)
аа
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
аа
NameError: name 'аа' is not defined
ff
<zip object at 0x0000013090F83C40>
tuple(ff)
((76, 'Соловьёва'), (85, 'Лыкова'), (94, 'Филиппова'), (103, 'Мельников'))
ff[0]
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
ff[0]
TypeError: 'zip' object is not subscriptable
fff=float(input('коэффициент усиления=')); dan=eval('5*fff-156')
коэффициент усиления=5
fff
5.0
fff=float(input('коэффициент усиления=')); dan=eval('5*fff-156')
коэффициент усиления=0
fff
0.0
fff=float(input('коэффициент усиления=')); dan=eval('5*fff-156')
коэффициент усиления=5
fff=float(input('коэффициент усиления=')); dan=eval('5*fff-156')
коэффициент усиления=5
fff
5.0
dan
-131.0
exec(input('введите инструкции:'))
введите инструкции:perem=-123.456;gg=round(abs(perem)+98,3)
пп
Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module>
пп
NameError: name 'пп' is not defined
gg
221.456
abs(-5)
5
pow(2, 3)
8
max([1, 5, 2])
5
min([1, 5, 2])
1
sum([1, 2, 3])
6
divmod(10, 3)
(3, 1)
len("abc")
3
list(map(str, [1, 2, 3]))
['1', '2', '3']
import math
dir(math)
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'cbrt', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'exp2', 'expm1', 'fabs', 'factorial', 'floor', 'fma', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'sumprod', 'tan', 'tanh', 'tau', 'trunc', 'ulp']
help(math.factorial)
Help on built-in function factorial in module math:
factorial(n, /)
Find n!.
math.factorial(5)
120
help(math.factorial)
Help on built-in function factorial in module math:
factorial(n, /)
Find n!.
math.sin(3.14)
0.0015926529164868282
math.acos(0.5)
1.0471975511965979
math.degrees(56)
3208.56365273261
math.degrees(1)
57.29577951308232
math.radians(57.29577951308232)
1.0
math.exp(1)
2.718281828459045
math.log(10)
2.302585092994046
math.log(2.302585092994046)
0.834032445247956
math.log10(100)
2.0
math.sqrt(16)
4.0
math.ceil(1.2)
2
math.floor(0.9)
0
math.pi
3.141592653589793
math.sin(2 * math.pi / 7 + math.exp(0.23))
0.8334902641414562
import cmath
dir(cmath)
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'cos', 'cosh', 'e', 'exp', 'inf', 'infj', 'isclose', 'isfinite', 'isinf', 'isnan', 'log', 'log10', 'nan', 'nanj', 'phase', 'pi', 'polar', 'rect', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau']
cmath.sqrt(1.2-0.5j)
(1.118033988749895-0.22360679774997896j)
cmath.phase(1-0.5j)
-0.4636476090008061
dir(random)
Traceback (most recent call last):
File "<pyshell#76>", line 1, in <module>
dir(random)
NameError: name 'random' is not defined. Did you forget to import 'random'?
import random
dir(random)
['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random', 'SG_MAGICCONST', 'SystemRandom', 'TWOPI', '_ONE', '_Sequence', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_accumulate', '_acos', '_bisect', '_ceil', '_cos', '_e', '_exp', '_fabs', '_floor', '_index', '_inst', '_isfinite', '_lgamma', '_log', '_log2', '_os', '_parse_args', '_pi', '_random', '_repeat', '_sha512', '_sin', '_sqrt', '_test', '_test_generator', '_urandom', 'betavariate', 'binomialvariate', 'choice', 'choices', 'expovariate', 'gammavariate', 'gauss', 'getrandbits', 'getstate', 'lognormvariate', 'main', 'normalvariate', 'paretovariate', 'randbytes', 'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', 'shuffle', 'triangular', 'uniform', 'vonmisesvariate', 'weibullvariate']
help(random.seed)
Help on method seed in module random:
seed(a=None, version=2) method of random.Random instance
Initialize internal state from a seed.
The only supported seed types are None, int, float,
str, bytes, and bytearray.
None or no argument seeds from current time or from an operating
system specific randomness source if available.
If *a* is an int, all bits are used.
For version 2 (the default), all of the bits are used if *a* is a str,
bytes, or bytearray. For version 1 (provided for reproducing random
sequences from older versions of Python), the algorithm for str and
bytes generates a narrower range of seeds.
random.seed()
a=random.seed()
a
random.random()
0.6199792494543297
random.uniform(1, 10)
7.745269197841402
random.randint(1, 6)
3
random.gauss(0, 1)
1.0442172814729307
random.choice(['a','b','c'])
'b'
lst = [1,2,3]; random.shuffle(lst)
random.shuffle(lst)
дые
Traceback (most recent call last):
File "<pyshell#90>", line 1, in <module>
дые
NameError: name 'дые' is not defined
lst
[3, 2, 1]
random.shuffle(lst)
lst
[3, 2, 1]
random.shuffle(lst)
lst
[3, 1, 2]
random.sample([1,2,3,4])
Traceback (most recent call last):
File "<pyshell#96>", line 1, in <module>
random.sample([1,2,3,4])
TypeError: Random.sample() missing 1 required positional argument: 'k'
random.sample([1,2,3,4], 2)
[4, 2]
random.sample([1,2,3,4], 2)
[2, 4]
random.sample([1,2,3,4], 2)
[3, 1]
random.betavariate(2, 5)
0.27219690103691246
random.gammavariate(2, 1)
2.5239555636492557
spisok = [random.uniform(1, 10), random.gauss(0, 1), random.betavariate(2, 5), random.gammavariate(2, 1)]
spisok
[4.813064235823525, -0.2439125318449509, 0.12581423894318752, 1.940336067871031]
import time
dir(time)
['_STRUCT_TM_ITEMS', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'altzone', 'asctime', 'ctime', 'daylight', 'get_clock_info', 'gmtime', 'localtime', 'mktime', 'monotonic', 'monotonic_ns', 'perf_counter', 'perf_counter_ns', 'process_time', 'process_time_ns', 'sleep', 'strftime', 'strptime', 'struct_time', 'thread_time', 'thread_time_ns', 'time', 'time_ns', 'timezone', 'tzname']
c1=time.time()
c2=time.time()-c1
c2
18.061716318130493
c1
1760287587.2442193
dat=time.gmtime()
dat
time.struct_time(tm_year=2025, tm_mon=10, tm_mday=12, tm_hour=16, tm_min=51, tm_sec=23, tm_wday=6, tm_yday=285, tm_isdst=0)
dat.tm_mon
10
dat.localtime
Traceback (most recent call last):
File "<pyshell#113>", line 1, in <module>
dat.localtime
AttributeError: 'time.struct_time' object has no attribute 'localtime'
localtime
Traceback (most recent call last):
File "<pyshell#114>", line 1, in <module>
localtime
NameError: name 'localtime' is not defined
time.localtime
<built-in function localtime>
local_time = time.localtime()
local_time
time.struct_time(tm_year=2025, tm_mon=10, tm_mday=12, tm_hour=19, tm_min=54, tm_sec=1, tm_wday=6, tm_yday=285, tm_isdst=0)
c1 = time.time()
local_struct = time.localtime(c1)
local_struct
time.struct_time(tm_year=2025, tm_mon=10, tm_mday=12, tm_hour=19, tm_min=59, tm_sec=42, tm_wday=6, tm_yday=285, tm_isdst=0)
time_str = time.asctime(local_struct)
time_str
'Sun Oct 12 19:59:42 2025'
time_str2 = time.ctime(c1)\
/
SyntaxError: multiple statements found while compiling a single statement
time_str2 = time.ctime(c1)
print(f"Год: {local_time.tm_year}")
Год: 2025
time.sleep(2)
time.sleep(2)
seconds = time.mktime(local_struct)
seconds
1760288382.0
new_struct = time.localtime(seconds)
new_struct
time.struct_time(tm_year=2025, tm_mon=10, tm_mday=12, tm_hour=19, tm_min=59, tm_sec=42, tm_wday=6, tm_yday=285, tm_isdst=0)
import pylab
Traceback (most recent call last):
File "<pyshell#134>", line 1, in <module>
import pylab
ModuleNotFoundError: No module named 'pylab'
import sys
sys.path.append(C:\\Users\Ekaterina\\AppData\\Roaming\\Microsoft\Windows\\Start Menu\\Programs\\Python 3.13)
SyntaxError: invalid character '' (U+2018)
import sys
sys.path.append('C:\\Users\Ekaterina\\AppData\\Roaming\\Microsoft\Windows\\Start Menu\\Programs\\Python 3.13')
import pylab
Traceback (most recent call last):
File "<pyshell#139>", line 1, in <module>
import pylab
ModuleNotFoundError: No module named 'pylab'
pip install matplotlib
SyntaxError: invalid syntax
import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<pyshell#143>", line 1, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
import pylab
x=list(range(-3,55,4))
t=list(range(15))
x
[-3, 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53]
t
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
pylab.plot(t,x)
[<matplotlib.lines.Line2D object at 0x00000130A1F4E990>]
pylab.title
<function title at 0x00000130A1BD8F40>
pylab.title('Первый график')
Text(0.5, 1.0, 'Первый график')
pylab.xlabel('время')
Text(0.5, 0, 'время')
pylab.ylabel('сигнал')
Text(0, 0.5, 'сигнал')
pylab.show()
X1=[12,6,8,10,7] и X2=[5,7,9,11,13]
SyntaxError: invalid syntax
X1=[12,6,8,10,7]
X2=[5,7,9,11,13]
pylab.plot(X1)
[<matplotlib.lines.Line2D object at 0x00000130A2AE2E90>]
pylab.plot(X2)
[<matplotlib.lines.Line2D object at 0x00000130A2AE2FD0>]
pylab.show()
pylab.show()
region=['Центр','Урал','Сибирь','Юг']
naselen=[65,12,23,17]
pylab.pie(naselen,labels=region)
([<matplotlib.patches.Wedge object at 0x00000130A1F397F0>, <matplotlib.patches.Wedge object at 0x00000130A24E8910>, <matplotlib.patches.Wedge object at 0x00000130A24E8CD0>, <matplotlib.patches.Wedge object at 0x00000130A24E8F50>], [Text(-0.191013134139045, 1.0832885038559115, 'Центр'), Text(-0.861328292412156, -0.6841882582231001, 'Урал'), Text(0.04429273995539947, -1.0991078896938387, 'Сибирь'), Text(0.9873750693480946, -0.48486129194837324, 'Юг')])
pylab.show()
data = [1, 2, 2, 3, 3, 3, 4, 4, 5]
plt.hist(data, 5)
Traceback (most recent call last):
File "<pyshell#167>", line 1, in <module>
plt.hist(data, 5)
NameError: name 'plt' is not defined
pylab.hist(data,5)
(array([1., 2., 3., 2., 1.]), array([1. , 1.8, 2.6, 3.4, 4.2, 5. ]), <BarContainer object of 5 artists>)
pylab.show()
c = ['A', 'B', 'C']
v = [10, 25, 15]
pylab..bar(c, v)
SyntaxError: invalid syntax
pylab.bar(c, v)
<BarContainer object of 3 artists>
pylab.show()
sred = statistics.mean(data)
Traceback (most recent call last):
File "<pyshell#175>", line 1, in <module>
sred = statistics.mean(data)
NameError: name 'statistics' is not defined. Did you forget to import 'statistics'?
import statistic
Traceback (most recent call last):
File "<pyshell#176>", line 1, in <module>
import statistic
ModuleNotFoundError: No module named 'statistic'
import statistics
sred = statistics.mean(data)
often = statistics.mode(data)
often
3
mediana = statistics.median(data)
mediana
3
moda = statistics.mode(data)

Загрузка…
Отмена
Сохранить