-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquadratic.py
More file actions
39 lines (30 loc) · 830 Bytes
/
quadratic.py
File metadata and controls
39 lines (30 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
import math
def quadratic (a,b,c):
q=b*b-4*a*c
if q < 0:
# return 'There is no result for your input'
print('There is no result for your input %s %s %s' % (a,b,c))
else:
x1=(-b+math.sqrt(q))/(2*a)
x2=(-b-math.sqrt(q))/(2*a)
print('The result for the quadratic is %.2f and %.2f' % (x1,x2))
num1=input('Please input first number:')
num2=input('Please input second number:')
num3=input('Please input third number:')
try:
num1=float(num1)
except ValueError:
print ('%s is not a number.' % num1)
exit()
try:
num2=float(num2)
except ValueError:
print ('%s is not a number.' % num2)
exit()
try:
num3=float(num3)
except ValueError:
print ('%s is not a number.' % num3)
exit()
quadratic(num1,num2,num3)