python菜鸟初学解方程

来学习的菜鸟 2017-03-16 10:36:23
>>> from __future__ import division
>>> import math
>>> def oneandtwo():
delta=a*x^2+b*x+c=0

SyntaxError: can't assign to operator
>>> def oneandtwo():
delta=b**2-4*a*c
print u'判别式大小为',delta
print
if delta<0:
print u'根的判别式小于0,方程无解!'
else:
x1=(-b+math.sqrt(delta))/(2*a)
x2=(-b-math.sqrt(delta))/(2*a)
print u'方程的两根是:\n\nx1=%f\nx2=%f'%(x1,x2)
print
if__name__=='__main__':

SyntaxError: invalid syntax
>>> if __name__=='__main__':
print u'输入一元二次方程的系数(a,b,c):'
print
stra=raw_input(u'请输入系数 a:')
strb=raw_input(u'请输入系数 b:')
strc=raw_input(u'请输入系数 c:')
print
print u'方程是:(%s)*x^2+(%s)*x+(%s)=0'%(stra,strb,strc)
print
a=float(stra)
b=float(strb)
c=float(strc)
oneandtwo()

输入一元二次方程的系数(a,b,c):

请输入系数 a:10
请输入系数 b:40
请输入系数 c:15

方程是:(10)*x^2+(40)*x+(15)=0


Traceback (most recent call last):
File "<pyshell#57>", line 13, in <module>
oneandtwo()
NameError: name 'oneandtwo' is not defined
>>>
以上是我照着打的代码帮看看那里错了,谢谢,原文章是http://blog.csdn.net/tooktang/article/details/8441037
...全文
382 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧