How to calculate a second degree equation
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|write your reason here}}.
This example shows how to easily resolve second degree equations using PySymbian.
Example Code
#Equations.py
#(c) Rafael Tavares 2008
import appuifw
from math import sqrt
op = 1
#Calculate
while (op!=2):
a = float(appuifw.query(u"A:", "text"))
b = float(appuifw.query(u"B:", "text"))
c = float(appuifw.query(u"C:", "text"))
#Delta
delta=b*b-4*a*c
#The equation answer is not a real number
if (delta<0):
appuifw.note(u"Equation answers are not real numbers", "error")
#The equation is possible
else:
x1=((b*-1)+sqrt(delta))/(2*a)
x2=((b*-1)-sqrt(delta))/(2*a)
continueoption=appuifw.popup_menu([u"Delta= "+u"%.0f" % (delta), u"x'= "+u"%.1f" % (x1), u"x''= "+u"%.1f" % (x2), u"Quit"])
if (continueoption==3): # Quit selected
op = 2
This article was written by Rafael T.


(no comments yet)