Python Learning notes (1)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.