# What's wrong with my code?

**URL:** <https://discuss.python.org/t/whats-wrong-with-my-code/16445>\
**Category:** Python Help\
**Tags:** help\
**Created:** [June 11, 2022, 2:27am UTC](https://discuss.python.org/t/whats-wrong-with-my-code/16445 "2022-06-11T02:27:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Norihiko](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/norihiko/32/7584_2.png) [@Norihiko](https://discuss.python.org/u/Norihiko)\
**Post date:** [June 11, 2022, 2:27am UTC](https://discuss.python.org/t/whats-wrong-with-my-code/16445/1 "2022-06-11T02:27:05Z")

</div>

import math

# I’m trying to calculate the zeros of a vertex form parabola. The code works when d is equals 0, but doesn’t otherwise.

a = float(input("Insert coefficient a: "))  
h = float(input("Insert coefficient h: "))  
k = float(input("Insert coefficient k: "))

d = -k/a

if d \>= 0:  
x\_1 = h + math.sqrt(d)  
x\_2 = h - math.sqrt(d)  
else:  
x\_1 = h + math.sqrt((-k/a))  
x\_2 = complex(h),-math.sqrt((-k/a))

if d \> 0:  
print("x\u2081 = ", x\_1, " and x\u2082 = ", x\_2)  
elif d == 0:  
print("x\u2081 = ", x\_1, “. There is no x\u2082.”)  
else:  
print("Impossible with real numbers. ")  
print("x\u2081 = ", x\_1, " and x\u2082 = ", x\_2)

import time  
time.sleep(5)

import os  
import sys

restart = input("\nDo you want to restart the program? [y/n] \> ")

if restart == “y”:  
os.execl(sys.executable, os.path.abspath( **file** ), \*sys.argv)  
else:  
print(“\nThe program will be closed…”)  
sys.exit(0)

---

<div class="post-metadata">

**Author:** ![BowlOfRed](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bowlofred/32/3379_2.png) [@BowlOfRed](https://discuss.python.org/u/BowlOfRed)\
**Post date:** [June 11, 2022, 3:40pm UTC](https://discuss.python.org/t/whats-wrong-with-my-code/16445/2 "2022-06-11T15:40:32Z")

</div>

Can you show what _does_ happen when you run it? Your code looks like it might work for d \> 0. The concerns I have are:

- Mixed quotes. All the quotes should be simple single `'` or double `"`. In the middle of your paste, some are complex quotes `”`. I don’t know if that’s an error with the paste or if that’s in your code. Python won’t interpret them as string delimiters though.
- You create `d = -k/a`, but then in several other places you don’t bother to use it, continuing to use `-k/a` in the code. You should be consistent and use one or the other.
- `math.sqrt()` can’t handle negative numbers to give complex answers. You probably want to be using `cmath.sqrt()` instead.
- running an exec to restart the program is overkill (and done incorrectly). Much better to just make a simple loop. Even a `while True:`. Then break if the answer to restart isn’t yes.
