Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to observe the end of the series?

The problem is that, I don’t know how to observe the end of the series.
What i mean:

variable = 1
variable = 2
variable = 3
(...)
variable = 14

This "variable" grows to a random number (for example: 14) and then suddenly drops to 0

variable = 0

The biggest problem is that I don’t know at what number the "drop" will occur.
How to detect this kind of behavior? (I want to save the number where it occurred, in this case it is "14") Has anyone ever had a similar problem to solve?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Sample code:

series = 0
i=1
while i==1:
   variable = 1 (web scraped data e.g "1")
   if variable ==1:
      series = series + 1
   else:
      series = 0

>Solution :

Two ways:

1 – You can create a global variable to store the max value of variable in each iteration

max_value = None
while <condition>:
  if variable > max_value: max_value = variable 
  ....

2 – Using List, and get a max of the list. This way you can store all occurrences of the variable

valueList = []
while <condition>:
  valueList.append(variable)
  ....
max_vale=max(valueList) #after the while loop
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading