1. Ask for a prime number between 50 and 100
Import Math for in range (50,100+1): A in range (2,int (math.sqrt (i)) +1): if i%j==0: break Else: print(i )
View Code
2. Solving the solution of a unary two-time equation: Ax2+bx+c=0
ImportMathdefQuad (a,b,c):if notIsinstance (A, (int,float)) andIsinstance (b, (int,float)) andIsinstance (c, (int,float)):RaiseTypeError ('Bad operand type') return 'abc\ ' re Error' Else: ifA==0 andb!=0:return(-c)/belifA==0 andd={0:return 'abc\ ' re Error' Else: M=b*b-4*a*Cifm>=0:x1= (-b+math.sqrt (m))/(a) X2= (-b-math.sqrt (m))/(a)ifx1==X2:returnX1Else: returnx1,x2Else: returnComplex ((-B)/(2*a), (Math.sqrt (-M))/(2*a)), complex ((-B)/(2*a),-(Math.sqrt (-M))/(a)) A=int (Input ('plz input A:')) b=int (Input ('plz input B:')) C=int (Input ('plz input c:')) S=Quad (a,b,c)Print(s)View Code
Python Learning notes (1)