[Python][Development] Quadratic Equation Solver

Status
Not open for further replies.

Jeisa

Member
May 4, 2011
112
2
I've made this program that solves quadratic equations, but I am stuck when the discriminant is negative, i want my program to say
Code:
print 'Discriminant is negative, there are no roots, done!'
is there a code that i can use when answer is negative for it to stop? like
Code:
if ans == -ans:
print 'No roots'
Code:
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    start()
  File "C:\Users\Home\Desktop\python\quadraticequation.py", line 17, in start
    ansadd=-b+dis**.5
ValueError: negative number cannot be raised to a fractional power

That is the error I get, after my discriminant is negative!

Help please?
Thanks

EDIT 5/31/11: Everything is fixed and running, all I need is to convert it into an exe. Any ideas? I already tried py2exe but doesnt work for me :/
 

Dayron1234

Rapnameiszero,cuzIhavezero,toleranceforidiots
Jun 30, 2010
772
35
You could just make a calculator in Python which I did(Lost files but I can re-do it thanks to google) :)
 

Meap

Don't need glasses if you C#
Nov 7, 2010
1,045
296
:eek: calculator
I like them
I cheat in tests with them
try creating like a game in python :)
 

Dayron1234

Rapnameiszero,cuzIhavezero,toleranceforidiots
Jun 30, 2010
772
35
I already did that in Python kinda fun with you get really bored lol
 

Meap

Don't need glasses if you C#
Nov 7, 2010
1,045
296
one question
whats python
is it any good?
but I really want this stuff
I can cheat in tests >:]
 

Dayron1234

Rapnameiszero,cuzIhavezero,toleranceforidiots
Jun 30, 2010
772
35
Python is just a basic coding program and lucky for you I found the files that I coded last year lol

Code:
#Find the key! coded by me :D

#the menu function:
def menu(list, question):
    for entry in list:
        print 1 + list.index(entry),
        print ") " + entry

    return input(question) - 1

#Give the computer some basic information about the room:
items = ["pot plant","painting","vase","lampshade","shoe","door"]

#The key is in the vase (or entry number 2 in the list above):
keylocation = 2

#You haven't found the key:
keyfound = 0

loop = 1

#Give some introductary text:
print "Last night you went to sleep in the comfort of your own home."

print "Now, you find yourself locked in a room. You don't know how"
print "you got there, or what time it is. In the room you can see"
print len(items), "things:"
for x in items:
    print x
print ""
print "The door is locked. Could there be a key somewhere?"
#Get your menu working, and the program running until you find the key:
while loop == 1:
    choice = menu(items,"What do you want to inspect? ")
    if choice == 0:
        if choice == keylocation:
            print "You found a small key in the pot plant."

            print ""
            keyfound = 1
        else:
            print "You found nothing in the pot plant."
            print ""
    elif choice == 1:
        if choice == keylocation:
            print "You found a small key behind the painting."
            print ""

            keyfound = 1
        else:
            print "You found nothing behind the painting."
            print ""
    elif choice == 2:
        if choice == keylocation:
            print "You found a small key in the vase."
            print ""
            keyfound = 1
        else:
            print "You found nothing in the vase."

            print ""
    elif choice == 3:
        if choice == keylocation:
            print "You found a small key in the lampshade."
            print ""
            keyfound = 1
        else:
            print "You found nothing in the lampshade."
            print ""

    elif choice == 4:
        if choice == keylocation:
            print "You found a small key in the shoe."
            print ""
            keyfound = 1
        else:
            print "You found nothing in the shoe."
            print ""
    elif choice == 5:
        if keyfound == 1:
            loop = 0
            print "You put in the key, turn it, and hear a click"

            print ""
        else:
            print "The door is locked, you need to find a key."
            print ""

# Remember that a backslash continues
# the code on the next line

print "Light floods into the room as \
you open the door to your freedom."
 

Jeisa

Member
May 4, 2011
112
2
one question
whats python
is it any good?
but I really want this stuff
I can cheat in tests >:]

Python is a high-level programming language, and you can find more info about it at
And yes I'm practically done with the program, I might release it when its done, I just need that help lol!

Edit: Solved. Close please.
 
Status
Not open for further replies.

Users who are viewing this thread

Top