<> Chapter four is coming

<>1. Yanghui triangle , It's simple
print("1".center(20)) print("1 1".center(20)) print("1 2 1".center(20)) print(
"1 3 3 1".center(20)) print("1 4 6 4 1".center(20))
<>2. Triangle related problems , Please make a statement first math function .
import math a=float(input(" Please enter the right side of the right triangle A(A>0):")) b=float(input(
" Please enter the right side of the right triangle B(B>0):")) c=math.sqrt(a**2+b**2) zc=a+b+c mj=1/2*a*b sinA=b/c sinB
=a/c A=round(math.asin(sinA)*180/math.pi,0) B=round(math.asin(sinB)*180/math.pi,
0) print(str.format(" The three sides of a right triangle are ：a={0:.1f},b={1:.1f},c={2:.1f}",a,b,c)) print(str
.format(" The circumference of a triangle ={0:.1f}, the measure of area ={1:.1f}",zc,mj)) print(str.format(
" The degrees of the two acute angles of a triangle are ：{0:.1f} and {1:.1f}",A,B))
<>3. Sort random numbers . Pay attention to advance declaration random function
import random a=random.randint(0,100) b=random.randint(0,100) c=random.randint(
0,100) print(str.format(" Original value : a={0},b={1},c={2}",a,b,c)) ma=max(a,b,c) mi=min(a,
b,c) me=a+b+c-ma-mi print(str.format("（ Method 1 ） Ascending value ：a={0},b={1},c={2}",mi,me,ma)) if(
a>b):a,b=b,a if(a>c):a,c=c,a if(b>c):b,c=c,b print(str.format(
"（ Method 2 ） Ascending value ：a={0},b={1},c={2}",a,b,c))
<>4. On party expenses .
s=int(input(" Please input the monthly salary of the Party member with fixed salary ：")) f=1 if(s<=400): f=0.5/100*s elif(s>=401 and s
<=600): f=1/100*s elif(s>=601 and s<=800): f=1.5/100*s elif(s>=801 and s<=1500):
f=2/100*s else:f=3/100*s print(str.format(" Monthly salary ={0}, Pay Party fees {1:.1f}",s,f))
<>5. A simple calculator
x=float(input(" Please enter the operands x:")) y=float(input(" Please enter the operands y:")) c=str(input(" Please enter an operator ：")) z
=1 if(c=="+"): z=x+y print(str.format("{0}{1}{2}={3}",x,c,y,z)) elif(c=="-"): z=
x-y print(str.format("{0}{1}{2}={3}",x,c,y,z)) elif(c=="*"): z=x*y print(str.
format("{0}{1}{2}={3}",x,c,y,z)) elif(c=="/"): if(y==0):print(" The denominator is 0, Zero division exception ") else:
z=x/y print(str.format("{0}{1}{2}={3}",x,c,y,z)) else: if(y==0):print(
" The denominator is 0, Remainder exception ") else: z=x%y print(str.format("{0}{1}{2}={3}",x,c,y,z))
<>6. Judging triangle
a=float(input(" Please enter the edge of the triangle a:")) b=float(input(" Please enter the edge of the triangle b:")) c=float(input(
" Please enter the edge of the triangle c:")) ma=max(a,b,c) mi=min(a,b,c) if(a+b>c and a+b>c and b+c>a): if(a==
b==c):print(" This triangle is equilateral !") elif(a==b or a==c or b==c):print(" This triangle is isosceles triangle !") elif(
ma**2==mi**2+(a+b+c-ma-mi)**2):print(" This triangle is a right triangle ") else:print(" This triangle is an ordinary triangle ")
else:print(" Can't form a triangle ")
<>7. Chicken and rabbit in the same cage , Pay attention to the rational use of the existing relationship . If there is no solution, the number of feet must be greater than or equal to the number of heads .
h=int(input(" Please input the total number of heads : ")) f=int(input(" Please input the total number of pins ： ")) r=1;c=1 while(f%2!=0): print(
" The number of headers must be even ") f=int(input(" Please input the total number of pins ： ")) r=int(f/2-h) c=int(h-r) if(f<2*h):print(
" unsolvable , Please rerun the test !") else: print(" Method 1 ： chicken ：",c," only "","" rabbit : ",r," only ") for x in range(0,h+1):
if(2*x+4*(h-x)==f): print(" Method 2 ： chicken ：",x," only "","" rabbit : ",h-x," only ") break if(f<2*h): print
(" unsolvable , Please rerun the test !") break
<>8. calculation ex Approximate value of .
ex=1 n=1 j=1 x=float(input(" Please input x:")) w=1 while(w/j>=pow(10,-6)): w*=x j*=n n+=1
ex+=w/j print("pow(e,x)= ",ex)
<>9. Iterative method for square root , It's set here x The initial value of is 1/2a
import math a=float(input(" Please input a Value of ")) x=a/2 while(abs(x-math.sqrt(a))>pow(10,-6)
): x=0.5*(x+a/x) print(x)
<>10. Han Xin's question of ordering troops .
print("0~1000 of use 3 In addition to 2, use 5 In addition to 3, use 7 In addition to 2 What are the numbers ：") for i in range(0,1001): if(i%3==2 and i%5
==3 and i%7==2): print(str.format("{0:<5}",i),end="")
<>11. Small ball landing problem . Using arithmetic sequence to calculate , But the calculation here is different from the result given by the title , I don't know what's going on , So let's just take a look at this .
n=int(input(" Please enter page n Number of rebounds ")) an=50 sn=1 if n==1:sn=100 if n>1: sn=100+200*(1-pow
(0.5,n-1)) print(sn,an*pow(0.5,n-1))
<>12. Monkey stealing peach .
day=8 taozi=1 while(day>0): print(" The first %d The number of peaches per day is : %d"%(day,taozi)) taozi=(taozi+1)*2
day-=1 print(sn,an*pow(0.5,n-1))
<>13. Accumulation problem . recursion
import random n=random.randint(1,10) t=1 r=0 for i in range(1,n+1): r+=t t=10*t
+1 print(str.format('n={} Sn={}',n,r))
You can also define functions
import random n=random.randint(1,10) t=1 sn=1 def f(n): if n==1:return 1 if n>1
:return f(n-1)*10+1 for i in range(1,n): sn+=f(i) print("n= ",n,"sn= ",sn)
<>
I'm a little confused recently , I don't think my future of information management is very good , But also in a double non University of Finance and economics . The major is too broad , Learn but not master , Learn both computer and management , But it's hard to compete with other professionals . I searched my major in Zhihu , It is suggested that this major should be a database administrator , But after graduation, many companies don't necessarily need people without work experience , And the future is unpredictable . There should be more and more public clouds in the future , The company can hand over the database to a third party for management , In this way DBA There should be fewer and fewer jobs . I don't know what to do , Alas , That's so annoying .

Technology