feat: Initial commit
This commit is contained in:
24
Laboratorio7/esercizio1.py
Normal file
24
Laboratorio7/esercizio1.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from random import randint
|
||||
|
||||
def main():
|
||||
numbs = []
|
||||
|
||||
for i in range(10):
|
||||
numbs.append(randint(1, 100))
|
||||
|
||||
|
||||
print("Numeri con indici pari", numbs[1::2])
|
||||
#for i in range(0, len(numbs), 2):
|
||||
# print(i,":", numbs[i])
|
||||
|
||||
print("Numeri pari")
|
||||
for i in range(len(numbs)):
|
||||
if numbs[i] % 2 == 0:
|
||||
print(i,":", numbs[i])
|
||||
|
||||
print("Lista invertita", numbs[::-1])
|
||||
|
||||
print("Primo elemento", numbs[0])
|
||||
print("Ultimo elemento", numbs[-1])
|
||||
|
||||
main()
|
||||
19
Laboratorio7/esercizio2.py
Normal file
19
Laboratorio7/esercizio2.py
Normal file
@@ -0,0 +1,19 @@
|
||||
su = 0
|
||||
op = True
|
||||
|
||||
while True:
|
||||
inp = input("Inserisci un numero: ")
|
||||
|
||||
if inp == "":
|
||||
break
|
||||
|
||||
inp = int(inp)
|
||||
|
||||
if op:
|
||||
su += inp
|
||||
else:
|
||||
su -= inp
|
||||
|
||||
op = not op
|
||||
|
||||
print("La somma alternata è", su)
|
||||
33
Laboratorio7/esercizio3.py
Normal file
33
Laboratorio7/esercizio3.py
Normal file
@@ -0,0 +1,33 @@
|
||||
def removeDup(a):
|
||||
i=0
|
||||
while i < len(a) - 1:
|
||||
if a[i] == a[i + 1]:
|
||||
a.pop(i)
|
||||
else:
|
||||
i += 1
|
||||
|
||||
|
||||
def sameSet(a, b):
|
||||
cpa = list(a)
|
||||
cpb = list(b)
|
||||
|
||||
cpa.sort()
|
||||
cpb.sort()
|
||||
|
||||
removeDup(cpa)
|
||||
removeDup(cpb)
|
||||
|
||||
if len(cpa) == len(cpb):
|
||||
i=0
|
||||
while i < len(cpa):
|
||||
if cpa[i] != cpb[i]:
|
||||
break
|
||||
|
||||
i += 1
|
||||
|
||||
if i == len(cpa):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
print(sameSet([1,5,2,4,4,8], [1,1,4,2,8,5,5]))
|
||||
13
Laboratorio7/esercizio4.py
Normal file
13
Laboratorio7/esercizio4.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from random import randint
|
||||
|
||||
numbs = []
|
||||
|
||||
for i in range(20):
|
||||
numbs.append(randint(0, 99))
|
||||
print(i,":", numbs[i])
|
||||
|
||||
|
||||
numbs.sort()
|
||||
|
||||
for i in range(len(numbs)):
|
||||
print(i,":", numbs[i])
|
||||
26
Laboratorio7/esercizio5.py
Normal file
26
Laboratorio7/esercizio5.py
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
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
|
||||
|
||||
for i in range(1, len(nums) -1):
|
||||
if nums[i-1] < nums[i] > nums[i+1]:
|
||||
print("Massimo locale all'indice", i)
|
||||
maxFound = True
|
||||
|
||||
if not maxFound:
|
||||
print("Non ho trovato massimi locali")
|
||||
|
||||
main()
|
||||
3
Laboratorio7/esercizio6.py
Normal file
3
Laboratorio7/esercizio6.py
Normal file
@@ -0,0 +1,3 @@
|
||||
def sum_without_smallest(a):
|
||||
mini = min(a)
|
||||
return sum(a) - mini
|
||||
29
Laboratorio7/esercizio7.py
Normal file
29
Laboratorio7/esercizio7.py
Normal file
@@ -0,0 +1,29 @@
|
||||
def correzione(a):
|
||||
bb = a[0]
|
||||
a[0] = (a[0] + a[1]) / 2
|
||||
|
||||
for i in range(1, len(a)-1):
|
||||
xx = a[i]
|
||||
a[i] = (bb + a[i] + a[i+1])/3
|
||||
bb = xx
|
||||
|
||||
a[len(a)-1] = (bb + a[len(a)-1])/2
|
||||
|
||||
def readInts():
|
||||
ints = []
|
||||
|
||||
while True:
|
||||
num = input("Inserisci un numero: ")
|
||||
if num == "":
|
||||
break
|
||||
|
||||
ints.append(int(num))
|
||||
|
||||
return ints
|
||||
|
||||
def main():
|
||||
a = readInts()
|
||||
correzione(a)
|
||||
print(a)
|
||||
|
||||
main()
|
||||
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