Python Forum
Trapezoidal integration method in python. Getting wrong results
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trapezoidal integration method in python. Getting wrong results
#6
(Oct-14-2017, 05:20 PM)auting82 Wrote: Thanks, that worked.

Actually looking at it for second time, I think you need to unindent also line 7 in order to implement midpoint method

(Oct-14-2017, 05:20 PM)auting82 Wrote: As I am new to python, I am a bit confused on how to know if its an identation error as the program dosen't tell me Think ??

There is no indentation error in your code - it is valid python code and thus the interpreter does not raise any error. However it is incorrect in the sense that it does not implement the desired algorithm - because the return statement is within the for loop body, it actually exit the loop and the function after the first iteration, i.e. it does not finish the iteration. Understanding how your code works and what you want to do/implement will help you to identify such bugs. This comes with the experience and in more professional sense - the proper tests will help identify such errors in the code.

Now, your code in the post # 4 will indeed raise IndentationError because Python expects indented block after line 8. In fact you need to indent lines 9-12 one level, thus they will be executed for each iteration of the loop.
Reply


Messages In This Thread
RE: Trapezoidal integration method in python. Getting wrong results - by buran - Oct-14-2017, 07:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Active Directory integration dady 2 622 Oct-13-2023, 04:02 AM
Last Post: deanhystad
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 3,016 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Help with Integration Pandas excel - Python Gegemendes 5 2,058 Jun-05-2022, 09:46 PM
Last Post: Gegemendes
  How to save some results in .txt file with Python? Melcu54 4 7,651 May-26-2021, 08:15 AM
Last Post: snippsat
Photo Integration of apache spark and Kafka on eclipse pyspark aupres 1 3,921 Feb-27-2021, 08:38 AM
Last Post: Serafim
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,367 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  Tableau Time Series Prediction using Python Integration tobimarsh43 0 2,007 Jul-24-2020, 10:38 AM
Last Post: tobimarsh43
  R-PYTHON INTEGRATION RELATED PROBLEM arnab93 0 1,512 Jun-05-2020, 02:07 PM
Last Post: arnab93
  STATA/Python Integration jprender 0 1,920 May-03-2020, 09:38 PM
Last Post: jprender
  How to append one function1 results to function2 results SriRajesh 5 3,367 Jan-02-2020, 12:11 PM
Last Post: Killertjuh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020