【问题标题】:How to write this do...while from C++ to Python? [duplicate]从 C++ 到 Python,如何写这个? [复制]
【发布时间】:2020-09-01 15:23:56
【问题描述】:

从 C++ 到 Python 时如何编写这个 do...??

看了很多题目,不明白怎么写这样的功能


do

     { L = 0; x = a; h = h / 2;  

       while (x < b) {

           y1 = fC(x);

           y2 = fC(x+h);

           L = L + sqrt(h * h + (y2-y1) * (y2-y1)); 

           x = x + h;

       }

       L = L * 2;

    }

while (fabs(L0 - L) / L0 > 0.0001);

【问题讨论】:

    标签: python c++


    【解决方案1】:
    while True:  # do --> while True:
       L = 0 
       x = a
       h = h / 2
       while x < b:
           y1 = fC(x)
           y2 = fC(x+h)
           L = L + sqrt(h * h + (y2-y1) * (y2-y1)) 
           x = x + h
       L = L * 2
       if fabs(L0 - L) / L0 > 0.0001: break # do's while --> if ... : break
    

    【讨论】:

      猜你喜欢
      • 2021-12-25
      • 2018-10-02
      • 1970-01-01
      • 2013-05-21
      • 1970-01-01
      • 2011-08-18
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      相关资源
      最近更新 更多