Discuss / Python / 解方程计算器

解方程计算器

Topic source

张宇炘

#1 Created at ... [Delete] [Delete and Lock User]

from os import system

-- coding: utf-8 --

import math print('请分别输入一元二次方程ax^2+bx+c=0的三个参数 a, b, c') a=int(input()) b=int(input()) c=int(input()) def roots(a, b, c): n1=((-b+math.sqrt(bb-4ac))/(2a)) n2=((-b-math.sqrt(bb-4ac))/(2a)) return n1, n2 if a==0: def root(a, b, c): n3=((-c)/b) return n3 print('一元二次方程ax^2+bx+c=0的根为:', 'x= %s' %root(a, b, c)) elif (bb-4ac)<0: print('此方程无实根') elif (bb-4ac)==0: def root0(a, b, c): n4=((-b)/(2*a)) return n4 print('一元二次方程ax^2+bx+c=0有两重根:', 'x=%s' %root0(a, b, c)) else: print('一元二次方程ax^2+bx+c=0的根为:x=', roots(a, b, c)) system('pause')

我想知道,你写这些代码能运行么?


  • 1

Reply