feat: Initial commit
This commit is contained in:
11
Laboratorio5/fattorizzazione.py
Normal file
11
Laboratorio5/fattorizzazione.py
Normal file
@@ -0,0 +1,11 @@
|
||||
n = 12345678901234567890 #int(input("Numero: "))
|
||||
|
||||
k = 2
|
||||
|
||||
while n > 1:
|
||||
for x in range(k,n+1):
|
||||
if n % x == 0:
|
||||
print(x)
|
||||
k = x
|
||||
n = int(n/x)
|
||||
break
|
||||
30
Laboratorio5/fattorizzazionecrivellata.py
Normal file
30
Laboratorio5/fattorizzazionecrivellata.py
Normal file
@@ -0,0 +1,30 @@
|
||||
primeList = []
|
||||
lastIndex = 2
|
||||
|
||||
def primeListGenerator():
|
||||
global primeList, lastIndex
|
||||
|
||||
isPrime = True
|
||||
|
||||
for primeNumber in primeList:
|
||||
if lastIndex % primeNumber == 0:
|
||||
isPrime = False
|
||||
break
|
||||
|
||||
if isPrime:
|
||||
primeList.append(lastIndex)
|
||||
|
||||
lastIndex += 1
|
||||
|
||||
|
||||
|
||||
n = 12345678901234567890 # int(input("Numero: "))
|
||||
|
||||
k = 2
|
||||
|
||||
while n > 1:
|
||||
primeListGenerator()
|
||||
prime = primeList[-1]
|
||||
while n % prime == 0:
|
||||
n = int(n/prime)
|
||||
print(prime)
|
||||
19
Laboratorio5/lefrancesi.py
Normal file
19
Laboratorio5/lefrancesi.py
Normal file
@@ -0,0 +1,19 @@
|
||||
eccezioni = ["Belize", "Cambodge", "Mexique", "Mozambique", "Zaïre", "Zimbabwe"]
|
||||
|
||||
def main():
|
||||
nazione = input("Nome nazione")
|
||||
|
||||
if nazione == "Etats-Unis" or nazione == "Pays-Bas":
|
||||
print("les", nazione)
|
||||
return
|
||||
|
||||
if nazione[0].lower() in "aeiou":
|
||||
print("l'", nazione)
|
||||
return
|
||||
|
||||
if nazione in eccezioni or nazione[-1] != "e":
|
||||
print("le", nazione)
|
||||
else:
|
||||
print("la", nazione)
|
||||
|
||||
main()
|
||||
17
Laboratorio5/pin.py
Normal file
17
Laboratorio5/pin.py
Normal file
@@ -0,0 +1,17 @@
|
||||
def main():
|
||||
pin = "1234"
|
||||
errCount = 0
|
||||
|
||||
while errCount < 3:
|
||||
uinput = input("Insert pin: ")
|
||||
|
||||
if uinput == pin:
|
||||
print("Your PIN is correct")
|
||||
return
|
||||
|
||||
print("Your PIN is incorrect")
|
||||
errCount += 1
|
||||
|
||||
print("You bank card is blocked")
|
||||
|
||||
main()
|
||||
20
Laboratorio5/predatorepreda.py
Normal file
20
Laboratorio5/predatorepreda.py
Normal file
@@ -0,0 +1,20 @@
|
||||
A = float(input("Parametro A: "))
|
||||
B = float(input("Parametro B: "))
|
||||
C = float(input("Parametro C: "))
|
||||
D = float(input("Parametro D: "))
|
||||
|
||||
prede = float(input("Prede: "))
|
||||
predatori = float(input("Predatori: "))
|
||||
|
||||
intervalli = float(input("Iterazioni: "))
|
||||
|
||||
for i in range(intervalli):
|
||||
prede *= 1+A-B*predatori
|
||||
predatori *= 1-C+D*prede
|
||||
|
||||
if prede < 0:
|
||||
print("Prede estinte all'iterazione ", i)
|
||||
if predatori < 0:
|
||||
print("Predatori estinti all'iterazione ", i)
|
||||
|
||||
print("Predatori ", predatori, "; prede ", prede)
|
||||
21
Laboratorio5/prevendita.py
Normal file
21
Laboratorio5/prevendita.py
Normal file
@@ -0,0 +1,21 @@
|
||||
bigliettiRimasti = 100
|
||||
acquirenti = 0
|
||||
|
||||
while bigliettiRimasti > 0:
|
||||
biglietti = int(input("Quanti biglietti vuoi acquistare? "))
|
||||
|
||||
if biglietti < 1:
|
||||
print("Non puoi vendere biglietti")
|
||||
continue
|
||||
if biglietti > 4:
|
||||
print("Non puoi acquistare più di quattro biglietti")
|
||||
continue
|
||||
elif bigliettiRimasti < biglietti:
|
||||
print("Non sono disponibili abbastanza biglietti")
|
||||
continue
|
||||
|
||||
print("Acquisto effettuato")
|
||||
acquirenti += 1
|
||||
bigliettiRimasti -= biglietti
|
||||
|
||||
print("Acquirenti", acquirenti)
|
||||
10
Laboratorio5/pseudorandom.py
Normal file
10
Laboratorio5/pseudorandom.py
Normal file
@@ -0,0 +1,10 @@
|
||||
def pseudorandom(a, b, m, r):
|
||||
while True:
|
||||
r = (a*r+b)%m
|
||||
yield r
|
||||
|
||||
rold = int(input("Seed the generator: "))
|
||||
generator = pseudorandom(32310901, 1729, 2**24, rold)
|
||||
|
||||
for i in range (100):
|
||||
print(next(generator))
|
||||
Reference in New Issue
Block a user