Login
A   A   A  
welcome

 Album 

米Teen唔鐘意玩現成品,喜歡由零件開始砌。99次失敗唔係問題,最緊要係有1次成功!

米Teen總部設在聖公會白約翰會督中學506室,在午膳後和放學後集會。有興趣參與的同學,請與會長或導師聯絡。

米Teen專頁

街景
2025-08-08 22:42:36
Rm506 溫度31℃ 濕度90%
2025-08-07 11:29:14
LIGHT Noise 0 0


2025-08-07 13:53:08
LIGHT Disturber 0 0


2025-08-07 13:53:47
LIGHT Disturber 0 0


2025-08-08 10:49:02
LIGHT Lightning 31 0


2025-08-08 10:53:12
LIGHT Disturber 0 0


2025-08-08 11:01:14
LIGHT Disturber 0 0


2025-08-08 12:14:42
LIGHT Lightning 14 2


2025-08-08 14:03:06
LIGHT Disturber 0 0


2025-08-08 17:32:12
LIGHT Disturber 0 0


2025-08-08 17:32:13
LIGHT Disturber 0 0


Find all local maxima.

icon

Home>ICT>Python by ...>Find all l...

Find all the local maxima in a series.

1# Author: HUANG KWUN HOI (SKHBBSS, class 4D)
2# Last modified: 2020.9.5
3file=open(r'p00300data.txt', 'r') # Put the data file here!
4local_maximas=[]
5list1=[]
6previous_datum=0
7current_datum=0
8next_datum=0
9for data in file:
10 list1.append(int(data))
11 next_datum=int(data)
12 if current_datum>previous_datum and current_datum>next_datum:
13 local_maximas.append(current_datum)
14 previous_datum=current_datum
15 current_datum=next_datum
16file.close()
17last_data=list1[-1]
18second_last_data=list1[-2]
19if last_data>second_last_data:
20 local_maximas.append(last_data)
21print('local maximas: ', local_maximas)

Download source code

Download data file

welcome

 Album 

米Teen唔鐘意玩現成品,喜歡由零件開始砌。99次失敗唔係問題,最緊要係有1次成功!

米Teen總部設在聖公會白約翰會督中學506室,在午膳後和放學後集會。有興趣參與的同學,請與會長或導師聯絡。

米Teen專頁

街景
2025-08-08 22:42:36
Rm506 溫度31℃ 濕度90%
2025-08-07 11:29:14
LIGHT Noise 0 0


2025-08-07 13:53:08
LIGHT Disturber 0 0


2025-08-07 13:53:47
LIGHT Disturber 0 0


2025-08-08 10:49:02
LIGHT Lightning 31 0


2025-08-08 10:53:12
LIGHT Disturber 0 0


2025-08-08 11:01:14
LIGHT Disturber 0 0


2025-08-08 12:14:42
LIGHT Lightning 14 2


2025-08-08 14:03:06
LIGHT Disturber 0 0


2025-08-08 17:32:12
LIGHT Disturber 0 0


2025-08-08 17:32:13
LIGHT Disturber 0 0


 ⇧