Best Python code snippet using pytest-benchmark
lab7.py
Source:lab7.py
1import math2import matplotlib.pyplot as plt3def solve_dir(x):4 return 2 - 1 / (math.log(10) * x ** 2)5def solve(x):6 return x ** 2 + math.log10(x)7def integrate(x, m_i, m_next, h):8 return ((h / 2) * (solve(x) + solve(x + h))) - ((h ** 3 / 24) * (m_i + m_next))9def div(x, m_i, m_next, h):10 return (m_i + 6 / h * (x - (x + h)) * (11 (solve(x + h) - solve(x)) / h - (m_next - 2 * m_i) / 3) + 6 / h ** 2 * (12 x - (x + h)) ** 2 * ((m_next + m_i) / 2 - (solve(x + h) - solve(x)) / h))13a = 0.414b = 0.915n = 1116h = (b - a) / 1017segment = [a + h * i for i in range(11)]18gov = [solve(i) for i in segment]19# нижнÑÑ Ð´Ð¸Ð°Ð³Ð¾Ð½Ð°Ð»Ñ20diag_1i = [0.5 if i != 9 else 1 for i in range(11 - 1)]21diag_1i.insert(0, 0)22# Ð³Ð»Ð°Ð²Ð½Ð°Ñ Ð´Ð¸Ð°Ð³Ð¾Ð½Ð°Ð»Ñ23diag_i = [2 for _ in range(11)]24# веÑÑ
нÑÑ Ð´Ð¸Ð°Ð³Ð¾Ð½Ð°Ð»Ñ25diag_i1 = [0.5 if i != 0 else 1 for i in range(11 - 1)]26diag_i1.append(0)27# векÑÐ¾Ñ Ð¿Ñавой ÑаÑÑи28resuilt = []29for i in range(11):30 if i == 0:31 resuilt.append((3 / h) * (gov[i + 1] - gov[i]) - (h / 2) * solve_dir(segment[i]))32 elif i == 10:33 resuilt.append((h * solve_dir(segment[i]) / 2) + 3 * ((gov[i] - gov[i - 1]) / h))34 else:35 resuilt.append(30 * (gov[i + 1] - gov[i - 1]))36def solveMatrix(n, a, c, b, f):37 m = 038 x = [0 for i in range(n)]39 for i in range(1, n):40 m = a[i] / c[i - 1]41 c[i] = c[i] - m * b[i - 1]42 f[i] = f[i] - m * f[i - 1]43 x[n - 1] = f[n - 1] / c[n - 1]44 for i in range(n - 2, -1, -1):45 x[i] = (f[i] - b[i] * x[i + 1]) / c[i]46 return x47# пÑимеÑ48mi = solveMatrix(11, diag_1i, diag_i, diag_i1, resuilt)49def S(x, i):50 res = 051 a1 = 6 / h52 a2 = (gov[i + 1] - gov[i]) / h53 a3 = (mi[i + 1] + 2 * mi[i]) / 354 a4 = 12 * (x - segment[i]) / (h ** 2)55 a5 = (mi[i + 1] + mi[i]) / 256 a6 = (gov[i + 1] - gov[i]) / h57 res += a1 * (a2 - a3) + a4 * (a5 - a6)58 return res59govS2 = []60for j, i in enumerate(segment):61 if j == 10:62 j = 963 govS2.append(S(i, j))64govy2 = [solve_dir(i) for i in segment]65plt.plot(segment, govy2)66plt.plot(segment, govS2)67plt.legend(['ФÑнкÑиÑ', 'Сплайн'], loc=2)...
work.py
Source:work.py
1# -*- coding:utf8 -*-2"""3 使ç¨æ¬å¨å¦ä¹ çææ¯æ¹é 第äºå¨ç计ç®å¨å®ç°ï¼å
¶ç®æ å¦ä¸ï¼4 1. è¿è¡åæ示让ç¨æ·è¾å
¥ä¸ä¸ªæ°å5 2. æ示è¾å
¥æä½ç¬¦ï¼+ - * /ï¼6 3. å次æ示è¾å
¥ä¸ä¸ªæ°å7 4. æå°è®¡ç®ç»æ8 5. å¨ä¸éåºç¨åºçåæä¸ï¼å¯ä»¥å
许ç¨æ·ç»§ç»è¾å
¥æ°ä¸ç»æ°æ®è®¡9 6. å°½å¯è½æ¹åç¨æ·ä½éªï¼æ°éæ±ï¼10"""11def Calculator(x, opt, y):12 if opt == "+":13 return x + y14 elif opt == "-":15 return x - y16 elif opt == "*":17 return x * y18 elif opt == "/":19 return x / y20 else:21 print("请æ£ç¡®è¾å
¥")22while True:23 x = float(input("请è¾å
¥æ°å: "))24 opt = input("请è¾å
¥+,-,*,/: ")25 y = float(input("请è¾å
¥æ°å: "))26 resuilt = Calculator(x, opt, y)...
Running_External_programs.py
Source:Running_External_programs.py
1import subprocess2resuilt = subprocess.run(['ls','-l'])...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!