# Отчет по теме 4 Корнеев Максим, А-03-23 ## 1 Стандартные функции ### 1.1 Функция round ```py >>> a = round(123.456,1) >>> a 123.5 >>> type(a) >>> b = round(123.456,0) >>> b 123.0 >>> type(b) >>> c = round(123.456) >>> c 123 >>> type(c) ``` ### 1.2 Функция range ```py >>> gg=range(76,123,9) >>> list(gg) [76, 85, 94, 103, 112, 121] >>> 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] ``` Список со значениями от 0 до 22 с шагом 1 ### 1.3 Функция zip ```py >>> qq = ['Корнеев','Гордиевских','Виноградов','Веретельников'] >>> ff=zip(gg,qq) >>> tuple(ff) ((76, 'Корнеев'), (85, 'Гордиевских'), (94, 'Виноградов'), (103, 'Веретельников')) >>> ff[0] Traceback (most recent call last): File "", line 1, in ff[0] TypeError: 'zip' object is not subscriptable ``` ### 1.4 Функция eval ```py >>> fff=float(input('коэффициент усиления=')); dan=eval('5*fff-156') коэффициент усиления=0.75 >>> dan -152.25 ``` ### 1.5 Функция exec ```py >>> exec(input('введите инструкции:')) введите инструкции:perem=-123.456;gg=round(abs(perem)+98,3) >>> gg 221.456 ``` ### 1.6 Некоторые другие функции ```py >>> abs(-123.8) 123.8 >>> pow(3,4,5) 1 >>> max([2,3,8,0,4,19]) 19 >>> min([2,3,8,0,4,19]) 0 >>> sum([2,3,8,0,4,19]) 36 >>> divmod(5,2) (2, 1) >>> len([2,3,8,0,4,19]) 6 >>> list(map(str, [1,2,3])) ['1', '2', '3'] ``` ## 2 Функции из стандартного модуля math ```py >>> dir(math) ['__doc__', '__file__', '__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'] >>> math.factorial(5) 120 >>> math.sin(0) 0.0 >>> math.acos(1) 0.0 >>> math.degrees(1) 57.29577951308232 >>> math.radians(57.29577951308232) 1.0 >>> math.exp(1) 2.718281828459045 >>> math.log(10,10) 1.0 >>> math.log10(100) 2.0 >>> math.sqrt(4) 2.0 >>> math.ceil(1.1) 2 >>> math.floor(2.9) 2 >>> math.pi 3.141592653589793 >>> math.sin((2*math.pi)/(7+math.exp(0.23))) 0.6895048136223224 ``` ## 3 Функции из модуля cmath ```py >>> dir(cmath) ['__doc__', '__file__', '__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 ``` ## 4 Стандартный модуль random ```py >>> 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'] >>> random.seed() >>> random.random() 0.09784937641299252 >>> random.uniform(0,1) 0.7586998848425669 >>> random.randint(1,10) 5 >>> random.gauss(1,1) 1.4114397784493207 >>> random.choice([0,3,4,12]) 3 >>> ss=[0,3,4,12] >>> random.shuffle(ss) >>> ss [12, 4, 3, 0] >>> random.sample(ss,2) [3, 12] >>> random.betavariate(1,1) 0.6955346411563408 >>> random.gammavariate(1,1) 1.2069826359988067 >>> spisok = [random.uniform(0, 1), random.gauss(0, 1), random.betavariate(1, 1), random.gammavariate(1, 1)] >>> spisok [0.976567712925113, 0.9183429804998575, 0.5079068978092008, 1.7131944904872685] ``` ## 5 Функции из модуля time ```py >>> dir(time) ['CLOCK_MONOTONIC', 'CLOCK_MONOTONIC_RAW', 'CLOCK_MONOTONIC_RAW_APPROX', 'CLOCK_PROCESS_CPUTIME_ID', 'CLOCK_REALTIME', 'CLOCK_THREAD_CPUTIME_ID', 'CLOCK_UPTIME_RAW', 'CLOCK_UPTIME_RAW_APPROX', '_STRUCT_TM_ITEMS', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'altzone', 'asctime', 'clock_getres', 'clock_gettime', 'clock_gettime_ns', 'clock_settime', 'clock_settime_ns', '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', 'tzset'] >>> c1=time.time() >>> c1 1760129676.087689 >>> c2=time.time()-c1 >>> c2 0.29564905166625977 >>> dat=time.gmtime() >>> dat time.struct_time(tm_year=2025, tm_mon=10, tm_mday=10, tm_hour=20, tm_min=55, tm_sec=16, tm_wday=4, tm_yday=283, tm_isdst=0) >>> dat.tm_mon 10 >>> dat.tm_year 2025 >>> dat.tm_hour 20 >>> dat.tm_mday 10 >>> time.localtime() time.struct_time(tm_year=2025, tm_mon=10, tm_mday=10, tm_hour=23, tm_min=57, tm_sec=26, tm_wday=4, tm_yday=283, tm_isdst=0) >>> time.asctime(dat) 'Fri Oct 10 20:55:16 2025' >>> time.ctime() 'Fri Oct 10 23:58:50 2025' >>> time.sleep(1) # Программа прервала свою работу на 1 секунду >>> time.mktime(dat) 1760118916.0 >>> time.localtime(c1) time.struct_time(tm_year=2025, tm_mon=10, tm_mday=10, tm_hour=23, tm_min=54, tm_sec=36, tm_wday=4, tm_yday=283, tm_isdst=0) ``` ## 6 Графические функции ```py >>> x=list(range(-3,55,4)) >>> t=list(range(15)) >>> pylab.plot(t,x) >>> pylab.title('Первый график') >>> pylab.xlabel('время') >>> pylab.ylabel('сигнал') >>> pylab.show() ``` Первый график: ![Первый график](Ris1.png) ```py >>> X1=[12,6,8,10,7] >>> X2=[5,7,9,11,13] >>> pylab.plot(X1) >>> pylab.plot(X2) >>> pylab.show() ``` Второй график: ![Второй график](Ris5.png) ```py >>> region=['Центр','Урал','Сибирь','Юг'] >>> naselen=[65,12,23,17] >>> pylab.pie(naselen,labels=region) >>> pylab.show() ``` Третий график: ![Третий график](Ris2.png) ```py >>> a = [1, 2, 5, 1, 5, 3, 2, 3, 1, 2, 1, 1, 2] >>> pylab.hist(a) >>> pylab.show() ``` Четвертый график: ![Четвертый график](Ris3.png) ```py >>> pylab.bar(region, naselen) >>> pylab.show() ``` Пятый график: ![Пятый график](Ris4.png) ## 7 Статистический модуль statistic ```py >>> dir(statistics) ['Counter', 'Decimal', 'Fraction', 'LinearRegression', 'NormalDist', 'StatisticsError', '_SQRT2', '__all__', '__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_coerce', '_convert', '_decimal_sqrt_of_frac', '_exact_ratio', '_fail_neg', '_float_sqrt_of_frac', '_integer_sqrt_of_frac_rto', '_isfinite', '_kernel_invcdfs', '_mean_stdev', '_newton_raphson', '_normal_dist_inv_cdf', '_quartic_invcdf', '_quartic_invcdf_estimate', '_random', '_rank', '_sqrt_bit_width', '_sqrtprod', '_ss', '_sum', '_triweight_invcdf', '_triweight_invcdf_estimate', 'acos', 'asin', 'atan', 'bisect_left', 'bisect_right', 'correlation', 'cos', 'cosh', 'count', 'covariance', 'defaultdict', 'erf', 'exp', 'fabs', 'fmean', 'fsum', 'geometric_mean', 'groupby', 'harmonic_mean', 'hypot', 'isfinite', 'isinf', 'itemgetter', 'kde', 'kde_random', 'linear_regression', 'log', 'math', 'mean', 'median', 'median_grouped', 'median_high', 'median_low', 'mode', 'multimode', 'namedtuple', 'numbers', 'pi', 'pstdev', 'pvariance', 'quantiles', 'random', 'reduce', 'repeat', 'sin', 'sqrt', 'stdev', 'sumprod', 'sys', 'tan', 'tau', 'variance'] >>> statistics.median(naselen) 20.0 >>> statistics.variance(naselen) 588.25 >>> x = [1,2,3,4,5] >>> y = [3,4,6,8,13] >>> statistics.correlation(x,y) 0.9577042613611466 >>> k, b = statistics.linear_regression(x,y) >>> k; b 2.4 -0.39999999999999947 ```