Python TypeError: must be str, not int

Python TypeError: must be str, not int

我在 Windows 64 位上使用 Python 3.6.2,出现错误:A TypeError....

   A = 0
   ns = input('Input start:')
   nf = input('Input finish:')
   steps = input('Input steps:')
   for i in range(steps + 1):
       d_n = (nf-ns)/steps
       n = ns + i * d_n
       f_n = n*n
       A = A + f_n * d_n

   next


   print('Area is: ', A)

这是错误....

    Traceback (most recent call last):
      File "C:/Users/UNO/Documents/Python 3.6/Curve_Area2.py", line 5, in 
    <module>
        for i in range(steps + 1):
    TypeError: must be str, not int 

我想要这个结果....

Input start:3
Input finish:5
Input steps:100000
Area is:  32.66700666679996 

我不知道如何解决这个问题...请帮忙!!!!

编辑:抱歉。使用 int(input()) 来解决这个问题。输入函数给出 str.

ns = str(input('Input start:')

python3中的输入函数returns字符串,因此需要将ns、nf、steps的值转换为整数。
更改这些行

ns = input('Input start:')
nf = input('Input finish:')
steps = input('Input steps:')

ns = int(input('Input start:'))
nf = int(input('Input finish:'))
steps = int(input('Input steps:'))

这是您要查找的内容:

A = 0
ns = int(input('Input start:'))
nf = int(input('Input finish:'))
steps = int(input('Input steps:'))
start=[]
finish=[]

for i in range(steps + 1):
    d_n = (nf - ns) / steps

    n = ns + i * d_n
    f_n = n * n
    A = A + f_n * d_n




print('Area is : {} \n Start at {} \n Finish at {} \n steps {}'.format(A,ns,nf,steps))

输入:

Input start:3
Input finish:5
Input steps:1000

输出:

Area is : 32.70066799999998 
 Start at 3 
 Finish at 5 
 steps 1000