Python TypeError : must be str, 不是 int

标签 python math python-3.6

我在 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 

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

最佳答案

这里是你要找的:

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

关于Python TypeError : must be str, 不是 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46583409/

相关文章:

python - 最接近 R nlminb 的 Python scipy 求解器模拟?

c# - 将用户输入的字符串转换为数学函数

javascript - 使用html5 canvas在圆形中以不同 Angular 显示不同值

python - Python 中意想不到的复数

python 3.6 JsonResponse 问题

tensorflow - 带有图像和标量的 keras 生成器

python - 在 Django 中将 Self 定义为多个属性

python - Django 大变量存储

python - with ... : for . .. : 在一行中

python - 在 Django 中更新条件