feat: Initial commit
This commit is contained in:
2
Laboratorio4/elreverso.py
Normal file
2
Laboratorio4/elreverso.py
Normal file
@@ -0,0 +1,2 @@
|
||||
parola = input("Inserisci una parola: ")
|
||||
print(parola[::-1])
|
||||
18
Laboratorio4/forme.py
Normal file
18
Laboratorio4/forme.py
Normal file
@@ -0,0 +1,18 @@
|
||||
n = int(input("Inserisci n: "))
|
||||
|
||||
for x in range(n):
|
||||
print("*"*n)
|
||||
|
||||
print()
|
||||
|
||||
d = 2*n
|
||||
for x in range(0, d-1):
|
||||
a = 1 + x*2
|
||||
|
||||
if a > d - 1:
|
||||
a = d - 1 - (x - n + 1)*2
|
||||
|
||||
b = (d - 1 - a)
|
||||
c = int(b/2)
|
||||
|
||||
print(" "*c + "*"*a + " "*c)
|
||||
38
Laboratorio4/listanumeri.py
Normal file
38
Laboratorio4/listanumeri.py
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
pari = 0
|
||||
dispari = 0
|
||||
somma = 0
|
||||
|
||||
maxN = None
|
||||
minN = None
|
||||
lval = None
|
||||
|
||||
while True:
|
||||
ri = input("Inserisci un numero: ")
|
||||
|
||||
if ri == "":
|
||||
break
|
||||
|
||||
i = int(ri)
|
||||
|
||||
if maxN is None or maxN < i:
|
||||
maxN = i
|
||||
|
||||
if minN is None or minN > i:
|
||||
minN = i
|
||||
|
||||
if i % 2 == 0:
|
||||
pari += 1
|
||||
else:
|
||||
dispari += 1
|
||||
|
||||
somma += i
|
||||
print("Somma parziale: ", somma)
|
||||
|
||||
if lval == i:
|
||||
print("Duplicato: ", lval)
|
||||
else:
|
||||
lval = i
|
||||
|
||||
print("Valore minimo:", minN)
|
||||
print("Valore massimo:", maxN)
|
||||
31
Laboratorio4/nim.py
Normal file
31
Laboratorio4/nim.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from math import floor, log2
|
||||
from random import randint
|
||||
|
||||
biglie = randint(10, 100)
|
||||
giocaComputer = randint(0, 1) == 1
|
||||
intelligente = randint(0, 1) == 1
|
||||
|
||||
while biglie > 0:
|
||||
if giocaComputer:
|
||||
if intelligente:
|
||||
if biglie in [3, 7, 15, 31, 63]:
|
||||
biglie -= randint(1, floor(biglie/2))
|
||||
else:
|
||||
biglie -= 3
|
||||
else:
|
||||
biglie -= randint(1, floor(biglie/2))
|
||||
else:
|
||||
mbiglie = int(input("Quante biglie vuoi togliere? "))
|
||||
if mbiglie > floor(biglie/2):
|
||||
print("Non puoi togliere così tante biglie")
|
||||
continue
|
||||
|
||||
biglie -= mbiglie
|
||||
|
||||
giocaComputer = not giocaComputer
|
||||
|
||||
|
||||
if giocaComputer:
|
||||
print("Ha vinto il computer")
|
||||
else:
|
||||
print("Ha vinto il giocatore")
|
||||
24
Laboratorio4/primi.py
Normal file
24
Laboratorio4/primi.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import random
|
||||
|
||||
primeList = []
|
||||
|
||||
|
||||
def primeListGenerator(upperBound):
|
||||
global primeList
|
||||
|
||||
for i in range(2, upperBound):
|
||||
isPrime = True
|
||||
|
||||
for primeNumber in primeList:
|
||||
if i % primeNumber == 0:
|
||||
isPrime = False
|
||||
break
|
||||
|
||||
if isPrime:
|
||||
primeList.append(i)
|
||||
|
||||
|
||||
n = int(input("Fino a "))
|
||||
primeListGenerator(n)
|
||||
for n in primeList:
|
||||
print(n)
|
||||
32
Laboratorio4/stringheACaso.py
Normal file
32
Laboratorio4/stringheACaso.py
Normal file
@@ -0,0 +1,32 @@
|
||||
stringa = input("Inserisci una stringa: ")
|
||||
|
||||
for char in stringa:
|
||||
if char.isupper():
|
||||
print(char, end="")
|
||||
|
||||
print()
|
||||
|
||||
for char in range(1, len(stringa), 2):
|
||||
print(stringa[char], end="")
|
||||
|
||||
print()
|
||||
|
||||
for char in stringa:
|
||||
if char.lower() in "aeiou":
|
||||
print("_", end="")
|
||||
else:
|
||||
print(char, end="")
|
||||
|
||||
print()
|
||||
|
||||
sumCifre = 0
|
||||
for char in stringa:
|
||||
if char.isdigit():
|
||||
sumCifre += 1
|
||||
|
||||
print("Numero di cifre: ", sumCifre)
|
||||
|
||||
print("Posizioni delle vocali: ", end="")
|
||||
for char in range(len(stringa)):
|
||||
if stringa[char].lower() in "aeiou":
|
||||
print(char, end=" ")
|
||||
5
Laboratorio4/substrings.py
Normal file
5
Laboratorio4/substrings.py
Normal file
@@ -0,0 +1,5 @@
|
||||
stringa = input("Inserisci una stringa")
|
||||
|
||||
for subLen in range(1, len(stringa)+1):
|
||||
for ns in range(len(stringa)-subLen+1):
|
||||
print(stringa[ns:ns + subLen])
|
||||
Reference in New Issue
Block a user