Compare commits

..
7 Commits
Author SHA1 Message Date
davide ec89c94373 aggiunge esercizio 34 2026-04-09 16:01:24 +02:00
davide 934f3096e7 aggiunge esercizio 33 2026-04-09 12:24:25 +02:00
davide 510d65e2ba aggiunge esercizio 32 2026-04-09 11:57:35 +02:00
davide 23ee9ea2bd aggiunge esercizio 31 2026-04-09 10:05:25 +02:00
davide 2b0f8a20d0 aggiunge esercizio 30 2026-04-09 09:57:20 +02:00
davide 54f0947b5e aggiunge esercizio 29 2026-04-09 09:32:01 +02:00
davide b838d9bb42 aggiunge esercizio 28 2026-04-09 09:05:37 +02:00
7 changed files with 150 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
def mysplit(string):
words = []
word = ""
for char in string:
if char != " ":
word += char
else:
if word:
words.append(word)
word = ""
if word:
words.append(word)
return words
print(mysplit("To be or not to be, that is the question"))
print(mysplit("To be or not to be,that is the question"))
print(mysplit(" "))
print(mysplit(" abc "))
print(mysplit(""))
+22
View File
@@ -0,0 +1,22 @@
number = input("Inserisci un numero: ")
digits = [
["###", "# #", "# #", "# #", "###"], # 0
[" #", " #", " #", " #", " #"], # 1
["###", " #", "###", "# ", "###"], # 2
["###", " #", "###", " #", "###"], # 3
["# #", "# #", "###", " #", " #"], # 4
["###", "# ", "###", " #", "###"], # 5
["###", "# ", "###", "# #", "###"], # 6
["###", " #", " #", " #", " #"], # 7
["###", "# #", "###", "# #", "###"], # 8
["###", "# #", "###", " #", "###"], # 9
]
for row in range(5):
line = ""
for ch in number:
digit_index = int(ch)
segment = digits[digit_index][row]
line = line + segment + " "
print(line)
+47
View File
@@ -0,0 +1,47 @@
def cifra(messaggio, shift):
"""
Cifra il messaggio usando il cifrario di Cesare con lo spostamento dato.
- Lettere minuscole rimangono minuscole
- Lettere maiuscole rimangono maiuscole
- Caratteri non alfabetici (spazi, numeri, punteggiatura) rimangono invariati
"""
risultato = ""
for c in messaggio:
if c.islower():
base = ord('a')
codice = ord(c)
nuovo_codice = (codice - base + shift) % 26 + base
cifrato = chr(nuovo_codice)
calcolo = f"({codice} - {base} + {shift}) % 26 + {base} = {nuovo_codice}"
elif c.isupper():
base = ord('A')
codice = ord(c)
nuovo_codice = (codice - base + shift) % 26 + base
cifrato = chr(nuovo_codice)
calcolo = f"({codice} - {base} + {shift}) % 26 + {base} = {nuovo_codice}"
else:
cifrato = c
risultato += cifrato
return risultato
messaggio = input("Inserire un messaggio da cifrare: ")
shift = 0
while shift < 1 or shift > 25:
try:
shift = int(input("Inserire il valore di spostamento (1-25): "))
if shift < 1 or shift > 25:
print("Valore fuori intervallo. Inserire un numero tra 1 e 25.")
except ValueError:
print("Input non valido. Inserire un numero intero.")
testo_cifrato = cifra(messaggio, shift)
print(f"Messaggio cifrato: {testo_cifrato}")
+15
View File
@@ -0,0 +1,15 @@
iban = input("Inserisci un iban valido: ")
iban_ruotato = iban[4:]+iban[:4]
iban_numerico = ""
for c in iban_ruotato:
if c.isalpha():
iban_numerico += str(ord(c)-ord("A") + 10)
else:
iban_numerico += c
if int(iban_numerico) % 97 == 1:
print("Iban valido")
else:
print("Iban non valido")
+14
View File
@@ -0,0 +1,14 @@
def anagramma(parola1, parola2):
parola_1 = list(parola1)
parola_2 = list(parola2)
if sorted(parola_1) == sorted(parola_2):
print("Anagrami")
else:
print("Non anagrammi")
parola_uno = input("Inserisci 1 parola: ")
parola_due = input("Inserisci 2 parola: ")
anagramma(parola_uno, parola_due)
+17
View File
@@ -0,0 +1,17 @@
data = input("Inserisci la tua data di nascita (formato AAAA MM GG): ")
data_raw = data.replace(" ","")
def somma_data(data_da_sommare):
data = 0
for ch in data_da_sommare:
data += int(ch)
return data
a = somma_data(data_raw)
while a >= 10:
a = somma_data(str(a))
print("La cifra della vita è:", a)
+15
View File
@@ -0,0 +1,15 @@
str1 = input("Inserire la prima stringa: ")
str2 = input("Inserire la seconda stringa: ")
pos = 0
for ch in str1:
lettera = str2.find(ch, pos)
if lettera == -1:
print("No")
break
pos = lettera + 1
else:
print("Si")