Question

Python. The array C has multibel spicky peaks (+ , -). write a code that detect...

Python.

The array C has multibel spicky peaks (+ , -). write a code that detect the vlaues of all those peaks and sum them up.
C = [0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0.0011
-0.0031
0.0011
0.0034
-0.0039
0.0004
0.0052
-0.0045
-0.0025
0.0067
-0.0038
-0.0034
0.0077
-0.0034
-0.0054
0.0076
-0.0011
-0.0063
0.0068
0.0004
-0.0084
0.0061
0.0037
-0.0086
0.0018
0.0063
-0.0045
-0.0069
0.0078
0.0027
-0.0132
0.0054
0.0133
-0.0131
-0.0060
0.0180
-0.0037
-0.0169
0.0140
0.0128
-0.0210
0.0048
0.0218
-0.0158
-0.0134
0.0216
-0.0004
-0.0205
0.0121
0.0126
-0.0197
-0.0031
0.0186
-0.0130
-0.0115
0.0160
-0.0010
-0.0114
0.0091
0.0026
-0.0087
0.0035
0.0043
-0.0047
0.0002
0.0025
-0.0015
-0.0006
0.0011
0.0002
-0.0006
-0.0004
0.0008
-0.0002
0
0
0
0
0
0
0
0
0
0
0]

Homework Answers

Answer #1

Python Code:


c=[0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0.0011,
-0.0031,
0.0011,
0.0034,
-0.0039,
0.0004,
0.0052,
-0.0045,
-0.0025,
0.0067,
-0.0038,
-0.0034,
0.0077,
-0.0034,
-0.0054,
0.0076,
-0.0011,
-0.0063,
0.0068,
0.0004,
-0.0084,
0.0061,
0.0037,
-0.0086,
0.0018,
0.0063,
-0.0045,
-0.0069,
0.0078,
0.0027,
-0.0132,
0.0054,
0.0133,
-0.0131,
-0.0060,
0.0180,
-0.0037,
-0.0169,
0.0140,
0.0128,
-0.0210,
0.0048,
0.0218,
-0.0158,
-0.0134,
0.0216,
-0.0004,
-0.0205,
0.0121,
0.0126,
-0.0197,
-0.0031,
0.0186,
-0.0130,
-0.0115,
0.0160,
-0.0010,
-0.0114,
0.0091,
0.0026,
-0.0087,
0.0035,
0.0043,
-0.0047,
0.0002,
0.0025,
-0.0015,
-0.0006,
0.0011,
0.0002,
-0.0006,
-0.0004,
0.0008,
-0.0002,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0]

total=0
print("Peak elements are:")
for i in range(len(c)):
if(i==0):
if(c[i]>c[i+1]):
print(c[i])
total=total+c[i]
elif(i==len(c)-1):
if(c[i]>c[i-1]):
print(c[i])
total=total+c[i]
else:
if(c[i]>c[i-1] and c[i]>c[i+1]):
print(c[i])
total=total+c[i]
print("Sum of peak elements in c is:",total)
  
  
Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT