Начал изучение. Написал простенькое решение уровнения. Выдает ощибку. Что не так?
Python:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
def sqeq( a, b, c ) :
D = b*b - 4*a*c
if D < 0 :
return [ ]
else :
x1 = ( -b + math.sqrt( D ) ) / ( 2 * a )
x2 = ( -b - math.sqrt( D ) ) / ( 2 * a )
return [ x1, x2 ]
a2 = input( u"a: " )
a1 = input( u"b: " )
a0 = input( u"c: " )
X = sqeq( a2, a1, a0 )
print( X )
iMac-iMac:Choise imacos$ python choise1.py
a: 1
b: 5
c: 200
Traceback (most recent call last):
File "choise1.py", line 19, in <module>
X = sqeq( a2, a1, a0 )
File "choise1.py", line 7, in sqeq
D = b*b - 4*a*c
TypeError: can't multiply sequence by non-int of type 'str'
iMac-iMac:Choise imacos$
a: 1
b: 5
c: 200
Traceback (most recent call last):
File "choise1.py", line 19, in <module>
X = sqeq( a2, a1, a0 )
File "choise1.py", line 7, in sqeq
D = b*b - 4*a*c
TypeError: can't multiply sequence by non-int of type 'str'
iMac-iMac:Choise imacos$
Последнее редактирование: