feat: Initial commit
This commit is contained in:
33
Laboratorio9/Esercizio4.py
Normal file
33
Laboratorio9/Esercizio4.py
Normal file
@@ -0,0 +1,33 @@
|
||||
def nameOfBestCustomer(sales: list, customers: list):
|
||||
maxSale = sales[0]
|
||||
maxName = customers[0]
|
||||
|
||||
assert len(sales) == len(customers)
|
||||
|
||||
for i in range(1, len(sales)):
|
||||
if maxSale < sales[i]:
|
||||
maxSale = sales[i]
|
||||
maxName = customers[i]
|
||||
|
||||
return maxName
|
||||
|
||||
|
||||
def main():
|
||||
sales = []
|
||||
customers = []
|
||||
|
||||
while True:
|
||||
sale = int(input("Inserisci la spesa: "))
|
||||
|
||||
if sale == 0:
|
||||
break
|
||||
|
||||
name = input("Inserisci il nome del cliente: ")
|
||||
|
||||
sales.append(sale)
|
||||
customers.append(name)
|
||||
|
||||
print(nameOfBestCustomer(sales, customers))
|
||||
|
||||
|
||||
main()
|
||||
79
Laboratorio9/esercizio1.py
Normal file
79
Laboratorio9/esercizio1.py
Normal file
@@ -0,0 +1,79 @@
|
||||
def scambiaEstremi(a: list):
|
||||
c = a[0]
|
||||
a[0] = a[-1]
|
||||
a[-1] = c
|
||||
|
||||
|
||||
def ruotaDestra(a: list):
|
||||
c = a.pop()
|
||||
a.insert(0, c)
|
||||
|
||||
|
||||
def azzeraPari(a: list):
|
||||
for i in range(0, len(a), 2):
|
||||
a[i] = 0
|
||||
|
||||
|
||||
def maxL(a: list):
|
||||
b = a.copy()
|
||||
|
||||
for i in range(1, len(a) - 1):
|
||||
b[i] = max(a[i-1], a[i+1])
|
||||
|
||||
|
||||
def rimuoviCentrale(a: list):
|
||||
if len(a) % 2 == 0:
|
||||
mi = len(a) // 2
|
||||
a.pop(mi - 1)
|
||||
a.pop(mi - 1)
|
||||
return
|
||||
|
||||
mi = len(a) // 2
|
||||
a.pop(mi - 1)
|
||||
|
||||
|
||||
def pariInizio(a: list):
|
||||
x = 0
|
||||
for i in range(0, len(a), 2):
|
||||
a.insert(x, a.pop(i))
|
||||
x += 1
|
||||
|
||||
|
||||
def secondMax(a: list):
|
||||
if a[0] > a[1]:
|
||||
fmax = a[0]
|
||||
smax = a[1]
|
||||
else:
|
||||
fmax = a[1]
|
||||
smax = a[0]
|
||||
|
||||
for i in range(2, len(a)):
|
||||
if a[i] > fmax:
|
||||
smax = fmax
|
||||
fmax = a[i]
|
||||
elif a[i] > smax:
|
||||
smax = a[i]
|
||||
|
||||
return smax
|
||||
|
||||
|
||||
def isListOrdered(a: list):
|
||||
b = sorted(a)
|
||||
|
||||
for i in range(len(a)):
|
||||
if a[i] != b[i]:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def twoAdiacentDuplicates(a: list):
|
||||
for i in range(0, len(a) - 1):
|
||||
if i[0] == i[1]:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def twoDuplicates(a: list):
|
||||
return twoAdiacentDuplicates(sorted(a))
|
||||
37
Laboratorio9/esercizio2.py
Normal file
37
Laboratorio9/esercizio2.py
Normal file
@@ -0,0 +1,37 @@
|
||||
posti = [[10 , 20, 30], [10 , 20, 30], [10 , 20, 30]]
|
||||
|
||||
def searchInTable(prezzo):
|
||||
for i in range(len(posti)):
|
||||
for j in range(len(posti[i])):
|
||||
if posti[i][j] == prezzo:
|
||||
posti[i][j] = 0
|
||||
print("Posto prenotato con colonna", i, "riga", j)
|
||||
return
|
||||
|
||||
print("Nessun posto prenotabile con quel prezzo")
|
||||
|
||||
while True:
|
||||
ch = input("Vuoi inserire il posto o il prezzo? (posto/prezzo) ")
|
||||
|
||||
if ch == "posto":
|
||||
x = int(input("Inserisci la colonna: "))
|
||||
y = int(input("Inserisci la riga: "))
|
||||
|
||||
if x > len(posti) or x < 0:
|
||||
print("Colonna non valida")
|
||||
continue
|
||||
|
||||
if y > len(posti[x]) or y < 0:
|
||||
print("Riga non valida")
|
||||
continue
|
||||
|
||||
if posti[x][y] == 0:
|
||||
print("Il posto è già occupato")
|
||||
continue
|
||||
|
||||
posti[x][y] = 0
|
||||
print("Posto prenotato")
|
||||
|
||||
else:
|
||||
prezzo = input("Inserisci il prezzo: ")
|
||||
searchInTable(prezzo)
|
||||
15
Laboratorio9/esercizio3.py
Normal file
15
Laboratorio9/esercizio3.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def play():
|
||||
words = []
|
||||
words.append(input("Inserisci una parola: "))
|
||||
|
||||
while True:
|
||||
print(words)
|
||||
word = input("Inserisci una parola: ")
|
||||
|
||||
if words[-1][-2:] == word[0:2] and word not in words:
|
||||
words.append(word)
|
||||
else:
|
||||
print("Fine dei giochi")
|
||||
return
|
||||
|
||||
play()
|
||||
58
Laboratorio9/esercizio5.py
Normal file
58
Laboratorio9/esercizio5.py
Normal file
@@ -0,0 +1,58 @@
|
||||
def remMin(a: list):
|
||||
x = 0
|
||||
y = a[0]
|
||||
|
||||
for i in range(len(a)):
|
||||
if y > a[i]:
|
||||
y = a[i]
|
||||
x = i
|
||||
|
||||
a.pop(x)
|
||||
|
||||
|
||||
def remMax(a: list):
|
||||
x = 0
|
||||
y = a[0]
|
||||
|
||||
for i in range(len(a)):
|
||||
if y < a[i]:
|
||||
y = a[i]
|
||||
x = i
|
||||
|
||||
a.pop(x)
|
||||
|
||||
|
||||
def remOdd(a: list):
|
||||
for i in range(len(a)-1, -1, -1):
|
||||
if a[i] % 2 == 1:
|
||||
a.pop(i)
|
||||
|
||||
|
||||
def remLenNotTwo(a: list):
|
||||
for i in range(len(a)-1, -1, -1):
|
||||
if 10 > a[i] or a[i] > 99:
|
||||
a.pop(i)
|
||||
|
||||
|
||||
def printlistf(a):
|
||||
print(":".join(list(map(lambda n: str(n), a))))
|
||||
|
||||
|
||||
def main():
|
||||
nums = list(map(lambda n: int(n), input("Inserisci la lista di numeri: ").split(":")))
|
||||
|
||||
a1 = nums.copy()
|
||||
remMax(a1)
|
||||
remMin(a1)
|
||||
printlistf(a1)
|
||||
|
||||
a2 = nums.copy()
|
||||
remOdd(a2)
|
||||
printlistf(a2)
|
||||
|
||||
a3 = nums.copy()
|
||||
remLenNotTwo(a3)
|
||||
printlistf(a3)
|
||||
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user