2012-01-27 12:46:39 UTC
Source code:
----------------------------------------------------------------------------------------------------------------
# its in estonian but the strings of text doesn't have anything to do with the
# problem.
# ax^2 + bx + c = 0
import time
import math
import sys
import os
a = input("sisestage ruutliikme vaartus (a) ") # input a
time.sleep(1)
print "..."
b = input ("sisestage lineaarliikme vaartus (b) ") # input b
time.sleep(1)
print "..."
c = input ('sisestage vabaliikme vaartus (c) ') # input c
time.sleep(1)
x1 = (-b + (math.sqrt (b*b -4*a*c))) / (2*a)
x2 = (-b - (math.sqrt (b*b -4*a*c))) / (2*a)
print "Antud funktsiooni nullkohad" # x1, x2 = ...
time.sleep(1)
print "..."
print "x1"
print x1
print "x2"
print x2
Xh = -b/2*a
Yh = a*Xh*Xh+b*Xh+c
print "Antud funktsiooni haripunkti koordinaadid" # Xh, Yh = ...
time.sleep(1)
print "..."
print "Xh"
print Xh
print "Yh"
print Yh
def restart_program(): # restart, yes, no?
python = sys.executable
os.execl(python, python, * sys.argv)
if __name__ == "__main__":
answer = raw_input("Do you want to restart this program ? ")
if answer.strip() in "y Y yes Yes YES".split():
restart_program()
----------------------------------------------------------------------------------------------------------
Example of the error I get when all variables are positive:
(a) 2
...
(b) 4
...
(c) 5
Traceback (most recent call last):
File "C:\Users\kasutaja\Documents\Programs\Ruutfunktsioon.py", line 19, in
x1 = (-b + (math.sqrt (b*b -4*a*c))) / (2*a)
ValueError: math domain error
Any help would be greatly appreciated!