当前位置:网站首页>Process control (Part 1)
Process control (Part 1)
2022-07-25 15:02:00 【~ Wen~】
Hello everyone , I am a Python Bloggers in the field .
If you are a programming enthusiast, you can learn together , I send it here every day Python Basic knowledge of , And related code .
If there are any mistakes in the article , Please grant me your advice .
If you think the blogger's article is wrong , Please support the blogger for the third company
I always believe in a word : I believe that hard work will pay off , This return may be slow , But please believe that , As long as you stick to it, it will be better .
Series column :
Find the greatest common divisor and the least common multiple
Cycle basic exercises - Wan Zipian String exercises ( On
1. Special sequence summation
type : Process control
describe
The user enters a value less than 10 The positive integer , seek 1 + 12 + 123 + 1234 + …… Before n Sum of items , When input is greater than or equal to 10 when , Output “data error!”
Input format
One less than 10 The positive integer
Output format
Before the sequence n Items and or “data error!”
Example
Input :5
Output :13715num=int(input())
sum=1
temp=1
for i in range(2,num+1):
temp=temp*10+i
sum=sum+temp
if num>=10:
print("data error!")
else:
print(sum)2. Before the fractional series n Xiang He
describe
Enter a positive integer n, Calculate and output the sequence 1、-1/2、2/3、-3/5、4/8、-5/12... Before n Xiang He .
Input format
Enter a positive integer n
Output format
Before outputting the sequence in the form of floating-point numbers n Sum of items
Example
Input :2
Output :0.5n = int(input())
a, b = 1, 2
flag = -1
result = 1.0
for i in range(1, n):
result = result + flag * a / b
a, b = i + 1, a + b
flag = -flag
print(result)3. Factorial sum
describe
If a positive integer is equal to the sum of the factorials of the numbers that make up it , Then the positive integer is called factorial sum . For example, positive integers 145,1!+4!+5! be equal to 145, therefore 145 It's just a factorial and a number . Enter a positive integer , Calculate the sum of the factorials of its digits , Judge whether it is a factorial sum . When the input number is a factorial sum , Output “YES”, Otherwise output “NO”. Be careful : The highest bit of the entered positive integer is not 0.
Input format
A positive integer .
Output format
Output string “YES” or “NO”
Example 1
Input :145
Output :YES
Example 2
Input :1400
Output :NOimport math
n=input()
sum=0
for i in n:
num=math.factorial(int(i))
sum=sum+num
if sum==int(n):
print("YES")
else:
print("NO")
'''import math
n = input()
s = sum(math.factorial(int(i)) for i in n) # The derived type
if int(n) == s:
print('YES')
else:
print('NO') '''4. Calculate the pi
type : Process control
describe
According to the following Taylor series relationship , Successively accumulate the items whose absolute value is not less than the threshold , Find the value of pi .

Input format
Give less than... In one line 1 And greater than 0 The threshold of .
Output format
Output the approximate PI that meets the threshold condition , Accurate to the decimal point 6 position .
Example
Input :0.000001
Output :3.141591n=eval(input())
pi4=k=0
f=1
s=0
while abs(1/(2*k+1))>=n:
pi4=pi4+f/(2*k+1)
k=k+1
f=-f
print("{:6f}".format(4*pi4)) 5. seek e Approximate value B
type : Process control
describe
constants e You can use series 1+1/1!+1/2!+⋯+1/n! To approximate .
This problem requires that the formula be used to calculate e Approximate value , If the last item (1/n!) Less than the given threshold , Terminate calculation ( This item is not included in ).
Input format
Enter a value less than 1 As the threshold
Output format
The output satisfies the approximation of the threshold condition e, Keep the output after the decimal point 8 position .
Example
Input :0.00000001
Output :2.71828183import math
threshold=float(input())
e=1
n=1
while True:
if 1/math.factorial(n)<threshold:
break
else:
e=e+1/math.factorial(n)
n=n+1
print("{:.8f}".format(e))6. Find the zero point of the function by dichotomy
type : Process control
describe
Existing equations :f(x) = x5-15x4+85x3-225x2+274x-121, It is known that f(x) stay [1.5,2.4] Interval monotonic descent , And in this interval f(x)==0 There is only one root , Solve the root by dichotomy .
Input format
Enter a positive integer n, When f(x) Less than 10-n It is considered that the value of the function is 0
Output format
The output equation is in [1.5,2.4] Root of interval , Accurate to... After the decimal point 6 position
Example
Input :9
Output :1.849016def f(x):
return x ** 5 - 15 * x ** 4 + 85 * x ** 3 - 225 * x ** 2 + 274 * x - 121
def bisection_method(low, high):
while True:
mid = (low + high) / 2
if abs(f(mid)) < 1 * 10 ** -n:
return '{:.6f}'.format(mid)
elif f(mid) < 0:
high = mid
else:
low = mid
if __name__ == '__main__':
n = int(input())
Low, High = 1.5, 2.4
print(bisection_method(Low, High))7. Root finding of higher order equation
type : Process control
describe
Have function

It is known that f(1.5)>0,f(2.4)<0, And in [1.5,2.4] The interval has only one root , Find the root ( Assume that the polynomial value is less than 10-6 It can be approximated as 0). It is required to round to the decimal point 6 position
Input format
nothing
Output format
The equation is in [1.5,2.4] Root of interval
** Example **
Output :x.xxxxxx
def f(x):
return x ** 5 - 15 * x ** 4 + 85 * x ** 3 - 225 * x ** 2 + 274 * x - 121
x1 = 1.5
x2 = 2.4
while abs(f((x1 + x2) / 2)) > 1e-6:
if f((x1 + x2)/2)> 0:
x1 = (x1 + x2) / 2
else:
x2= (x1 + x2) / 2
print("{:.6f}".format((x1+x2)/2))
8. Calculate the function curve and x The area surrounded by the axis
type : Process control
describe
Calculate the function curve in the interval (a,b) And x The area surrounded by the axis , This area can be parallel to y Axially cut into small trapezoids of equal width , The area of each trapezoid can be approximately calculated , The sum of all trapezoidal areas is the function curve and x The area surrounded by the axis , That is, the integral value of the function in a given interval ,dx The smaller it is , The higher the trapezoidal approximation , The more accurate the result is , That is to say, the more segments the interval cuts , The more accurate the result .
Refer to the below , Calculation function sin(x) In the interval (a,b) And x The area surrounded by the axis ,a,b Input by user , The number of segments divided into sections is also entered by the user .

Input format
The input consists of two lines
The first line is two real numbers separated by spaces , Represents the integral interval (input().split() Space separated input can be cut into two parts )
The second line is a positive integer , Represents the number of segments
Output format
Integral value , The result is reserved 2 Decimal place
Example
Input :
-3.14 3.14
1000
Output :
4.00
# Trapezoidal upper bottom abs(math.sin(x + i * dx), Function value may be negative , use abs() Take its absolute value
# Trapezoidal bottom abs(math.sin(x + i * dx + dx)) , Function value may be negative , use abs() Take its absolute value
# The area formula of trapezoid :( Top and bottom + Bottom )× high ÷2, Use letters to indicate :S=(a+c)×h÷2
import math
a, b = map(float, input().split()) # Enter the start and end of the interval
n = int(input()) # Enter the number of interval segments
area = 0 # Initial value of area
x = a # Set the starting point x value
dx = abs(a - b) / n # Calculate the height between each cell , That is, the height of each small trapezoid
for i in range(n): # Traverse n Intervals , Calculate the area of each small trapezoid and add it up
area = area + dx * (abs(math.sin(x + i * dx)) + abs(math.sin(x + i * dx + dx))) / 2
print("{:.2f}".format(area)) # Output area value
9. The hundred mark system is converted to the five mark system ( loop )
type : Process control
describe
Write a student achievement conversion program , The user enters the student's grade of the hundred mark system , The score is greater than or equal to 90 And less than or equal to 100 The output of is “A”, The score is greater than or equal to 80 And less than 90 The output of is “B”, The score is greater than or equal to 70 And less than 80 The output of is “C”, The score is greater than or equal to 60 And less than 70 The output of is “D”, The score is less than 60 The output of is “E”. Output when the input data is illegal “data error!”. Users can input grades repeatedly for conversion , Output when entering a negative number “end” And end the program
Input format
Enter one floating-point number at a time , Represents the score of the hundred mark system ; Repeated input , Enter a negative number to end the program
Output format
According to each input value, output A、B、C、D、E A letter or "data error!" or "end". Output end When the program ends .
Example
Input :
88
99
56
156
-5
Output :
B
A
E
data error!
endwhile True:
score = eval(input())
if score < 0:
print('end')
break
elif score > 100:
print('data error!')
elif score >= 90:
print('A')
elif score >= 80:
print('B')
elif score >= 70:
print('C')
elif score >= 60:
print('D')
else:
print('E')Xiaobian talks freely :
The works published by Xiaobian are suitable for beginners to learn , If you are a beginner , You can study with Xiaobian , I send it here every day Python Basic knowledge of , And related code . If you think the small preparation is good , Focus on , give the thumbs-up , Collection . If there's anything wrong , Your advice are most welcome . I will accept with an open mind . If there's something you don't understand , You can write it by private mail , I will reply to you as soon as possible .
边栏推荐
- Niuke multi school E G J L
- [C题目]力扣876. 链表的中间结点
- Resource not found: rgbd_ Launch solution
- Overview of cloud security technology development
- 51 single chip microcomputer learning notes (2)
- 32 chrome调试工具的使用
- L1和L2正则化
- 39 simple version of millet sidebar exercise
- [C topic] Li Kou 88. merge two ordered arrays
- [Android] recyclerview caching mechanism, is it really difficult to understand? What level of cache is it?
猜你喜欢

Share a department design method that avoids recursion

I hope some suggestions on SQL optimization can help you who are tortured by SQL like me

D2. picking carrots (hard version) (one question per day)

51 single chip microcomputer learning notes (2)

37 元素模式(行内元素,块元素,行内块元素)

Award winning interaction | 7.19 database upgrade plan practical Summit: industry leaders gather, why do they come?

微信公众号正式环境上线部署,第三方公众平台接入

006操作符简介

冈萨雷斯 数字图像处理 第一章绪论

Browser based split screen reading
随机推荐
Go language founder leaves Google
45padding won't open the box
阿里云技术专家邓青琳:云上跨可用区容灾和异地多活最佳实践
Splice a field of the list set into a single string
Awk from entry to earth (24) extract the IP of the instruction network card
Quickly set up dobbo demo
awk从入门到入土(21)awk脚本调试
Yarn: the file yarn.ps1 cannot be loaded because running scripts is prohibited on this system.
006操作符简介
国联证券买股票开户安全吗?
云安全技术发展综述
[C题目]力扣876. 链表的中间结点
SSH服务器拒绝了密码
MySQL 45 talks about | 06 global locks and table locks: Why are there so many obstacles to adding a field to a table?
LeetCode_字符串_中等_151.颠倒字符串中的单词
直播课堂系统05-后台管理系统
Realsense ROS installation configuration introduction and problem solving
Implementation of redis distributed lock
没错,请求DNS服务器还可以使用UDP协议
处理ORACLE死锁
