Discuss / Python / zuoye_0408

zuoye_0408

Topic source

纸质盒子

#1 Created at ... [Delete] [Delete and Lock User]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math
def quadratic(a,b,c):
    q=b*b-4*a*c
    if q>0:
        x1=(-b+math.sqrt(q))/a/2
        x2=(-b-math.sqrt(q))/a/2
        return x1,x2
    elif q==0:
        x1=-b/a/2
        x2=x1
        return x1,x2
    else:
        pass
        return ()

print('input a,b,c :')
a=float(input('a:'))
b=float(input('b:'))
c=float(input('c:'))
q=quadratic(a,b,c)
q=set(list(q))
# print('q =',q)
if len(q)==2:
    for x in q:
        print(x)
elif len(q)==1:
    for x in q:
        print(x)
else:
    print('None')

很优美

import math

def math_x(a,b,c): maths=bb-4ac if a==0: x1=-c/b return x1 elif maths>0: x1=(-b+math.sqrt(maths))/2a x2=(-b-math.sqrt(maths))/2a return (x1,x2) elif maths==0: x1=-b/2a else: print('wujie') a=float((input('a的值是:'))) b=float((input('b的值是:')))

c=float((input('c的值是:'))) aflo=math_x(a,b,c) print(aflo)


  • 1

Reply