-1

enter image description here

a, b, c = input() 
d = b*b - 4ac 
if d > 0:
  print(+sqrt(d)-b/(2a))
  print(-sqrt(d)-b/(2a)) 
else:
print("No real roots")

This question is from an online python practice sample. I am new to learning python and also tried writing the same program in the code editor and it says no many syntax errors. Help!

aayushkrm
  • 1
  • 2
  • 1
    Hi, There are multiple mistakes in the code you shared. You are directly using algebraic notations like "4ac" which should actually be "4 * a * c". Please start with simple Hello World programs at first and then move on to more complex ones. – Swastik Mohapatra Feb 11 '21 at 08:33
  • @SwastikMohapatra This is a question from my test paper – aayushkrm Feb 11 '21 at 09:04

2 Answers2

0

Here would be a running solution, but as the other user in the command pointed out it would be better to start slowly and understand the concepts better

try:
    inputs=(input("Type in 3 consecutive numbers seperated with spaces:").split() )
    a,b,c = map(int, inputs)
except ValueError:
    print("This is not a whole number.")

d = b*b - 4*a*c 
if d > 0:
    print(+sqrt(d)-b/(2*a))
    print(-sqrt(d)-b/(2*a)) 
else:
    print("No real roots")
T1Berger
  • 445
  • 3
  • 10
  • then you need to convert your a,b,c - variables to integer values - because the input() funciton only returns a string – T1Berger Feb 11 '21 at 09:05
  • Can we use this for input "a, b, c = map(int, input("Enter three values: ").split())" – aayushkrm Feb 11 '21 at 09:09
0

After few tweaks, this program works as intended.

a, b, c = map(int, input("Enter three values: ").split())
d = b*b - 4*a*c
if d > 0:
    print(+sqrt(d)-b/(2*a))
    print(-sqrt(d)-b/(2*a))
else:
    print("No real roots")
    
aayushkrm
  • 1
  • 2