feat: Initial commit
This commit is contained in:
44
Laboratorio7/esercizio8.py
Normal file
44
Laboratorio7/esercizio8.py
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
def readInts():
|
||||
ints = []
|
||||
|
||||
while True:
|
||||
num = input("Inserisci un numero: ")
|
||||
if num == "":
|
||||
break
|
||||
|
||||
ints.append(int(num))
|
||||
|
||||
return ints
|
||||
|
||||
def main():
|
||||
nums = readInts()
|
||||
maxFound=False
|
||||
|
||||
maxes = []
|
||||
|
||||
for i in range(1, len(nums) -1):
|
||||
if nums[i-1] < nums[i] > nums[i+1]:
|
||||
print("Massimo locale all'indice", i)
|
||||
maxes.append(i)
|
||||
maxFound = True
|
||||
|
||||
if not maxFound:
|
||||
print("Non ho trovato massimi locali")
|
||||
return
|
||||
|
||||
if len(maxes) < 2:
|
||||
print("Ho trovato solo un massimo")
|
||||
return
|
||||
|
||||
a = maxes[0]
|
||||
b = maxes[1]
|
||||
|
||||
for i in range(2, len(maxes)):
|
||||
if maxes[i] - b < b - a:
|
||||
a = b
|
||||
b = maxes[i]
|
||||
|
||||
print("Gli indici dei due massimi più vicini fra loro sono", a, b)
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user