Newbie programmer question - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Newbie programmer question

Posts: 1Member
Hi,

I've only just started learning programming (with Python) and I've bumped into this problem. Here's a program I wrote to come up with the roots to a quadratic equation:

import math

def main():
print("This program determines the real roots of a quadratic equation of the form: ax^2 + bx + c.")
print
a = input("Enter the valus of a: ")
b = input("Enter the valus of b: ")
c = input("Enter the valus of c: ")

discriminant = math.sqrt(b * b - 4 * a * c)
alpha = (-b + discriminant)/(2 * a)
beta = (b - discriminant)/(2 * a)

print("The roots of the equation are: ", alpha, beta)

main()

And this leads to the error below:

[color=Red]Traceback (most recent call last):
File "C:UserszlyangDesktopha.py", line 15, in
main()
File "C:UserszlyangDesktopha.py", line 9, in main
discriminant = math.sqrt(b * b - 4 * a * c)
TypeError: can't multiply sequence by non-int of type 'str'[/color]

I had to resort to adding an int() to all my variables when calculating the discriminant, alpha and beta variables. It's pretty troublesome having to type int() over and over again.

Is there a more elegant solution? Thanks (: