Docsity
Docsity

Prepara i tuoi esami
Prepara i tuoi esami

Studia grazie alle numerose risorse presenti su Docsity


Ottieni i punti per scaricare
Ottieni i punti per scaricare

Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium


Guide e consigli
Guide e consigli


mappa esercizi python sql, Schemi e mappe concettuali di Sistemi Informatici

mappa esercizi Python e sql, proposti dal prof

Tipologia: Schemi e mappe concettuali

2025/2026

Caricato il 17/04/2026

salma-faiz-1
salma-faiz-1 🇮🇹

1

(1)

2 documenti

1 / 13

Toggle sidebar

Questa pagina non è visibile nell’anteprima

Non perderti parti importanti!

bg1
Esercizi python:
1. Write a function that takes three numbers A, B, C as input and
multiplies them.
def multiplies(a,b,c):
return(a*b*c)
print (multiplies(2,5,6))
def. multiplies(a,b,c)
return a*b*c
print (multiplies(6,4,2))
Write a function that takes in input the two sides of a right-angled
triangle (A, B) and calculates the hypotenuse
def angles(a,b):
return (((a**2)+(b**2))**(1/2))
print (angles(3,6))
2. Write a function that takes a person's name and age as input and
prints "Hi I'm X and I'm Y years old.”
def meet(name,age):
print(“Hi I’m “ + name + “ and I’m “ + str(age) + “ years old””)
meet(“Anna”,18)
3. Write a function that, given a price and a percentage discount,
calculates the discounted price.
def shop(price,percentage):
return (price*(100-percentage))/100
print (shop(100 , 20))
4. One sheet is 0.01mm thick. How many times should it be folded in
half to reach a thickness of 500mm? You can solve the problem with
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Anteprima parziale del testo

Scarica mappa esercizi python sql e più Schemi e mappe concettuali in PDF di Sistemi Informatici solo su Docsity!

Esercizi python:

1. Write a function that takes three numbers A, B, C as input and multiplies them. def multiplies(a,b,c): return(abc) print (multiplies(2,5,6)) def. multiplies(a,b,c) return abc print (multiplies(6,4,2)) Write a function that takes in input the two sides of a right-angled triangle (A, B) and calculates the hypotenuse def angles(a,b): return (((a2)+(b2))*(1/2)) print (angles(3,6)) 2. Write a function that takes a person's name and age as input and prints "Hi I'm X and I'm Y years old.” def meet(name,age): print(“Hi I’m “ + name + “ and I’m “ + str(age) + “ years old””) meet(“Anna”,18) 3. Write a function that, given a price and a percentage discount, calculates the discounted price. def shop(price,percentage): return (price(100-percentage))/ print (shop(100 , 20)) 4. One sheet is 0.01mm thick. How many times should it be folded in half to reach a thickness of 500mm? You can solve the problem with

a while loop. Write a function that will take in input the thickness of the sheet and a max thickness and returns the number of time it needs to be folded. def foglio(thickness,max): fold= while thickness<=max: thickness=thickness* fold=fold+ return fold print(foglio(0.01,500)) FATTO 2 VOLTE GIUSTO def conta_pieghe(spessore, limite): volte = 0 while spessore < limite: spessore = spessore * 2 volte = volte + 1 return volte print(conta_pieghe(0.01, 500))

5. Write a function to calculate the sum of the first N numbers. def somma(N): sum= n= while n<=N: sum=sum+n n=n+ return(sum) DA RIGUARDARE

sum=sum+numero avg=sum/N return avg print(average(6,1,10))

import random def average(N,x,y): sum= for i in range (N): num= random.randint(x,y) sum=sum+num avg=sum/N return avg print(average(5,2,23))

8. Create a program that generates a random number between 1 and 10 and asks the user to guess it. Provide feedback if the guess is too high or too low, and continue until the user guesses correctly import random def gioco_indovina(): # 1. Il computer sceglie un numero segreto tra 1 e 10 segreto = random.randint(1, 10) indovinato = False print("Ho scelto un numero tra 1 e 10. Prova a indovinarlo!") # 2. Continua a chiedere finché 'indovinato' non diventa True while not indovinato:

Chiediamo all'utente di inserire un numero

scelta = int(input("Inserisci il tuo numero: "))

3. Controlliamo il numero inserito

if scelta < segreto: print("Troppo basso! Riprova.") elif scelta > segreto: print("Troppo alto! Riprova.") else: print("Complimenti! Hai indovinato!") indovinato = True # Questo ferma il ciclo while

Facciamo partire il gioco

gioco indovina()

**9. list con il for:

  1. Example: Deleting negative values:** def positives(lista): for x in lista: if x<0:

def calcola_quadrati(numeri): nuova_lista = [] for n in numeri: nuova_lista.append(n**2) return nuova_lista print(calcola_quadrati([2, 3, 5]))

12. Create a function that, given a list of names, returns a list with the same names with a capital letter (name.capitalize() ). anna, marco, luigi > Anna, Marco, Luigi def rendi_maiuscolo(nomi): nuova_lista = [] for n in nomi: nuova_lista.append(n.capitalize()) return nuova_lista

Test: ["anna", "marco", "luigi"] -> ["Anna", "Marco", "Luigi"]

print(rendi_maiuscolo(["anna", "marco", "luigi"])) 12.1. Modify the same function so that it removes all names starting with ”a” OR “A” (use indexes) x[0] == “a” anna, marco, luigi > Marco, Luigi def filtra_iniziale_a(nomi): nuova_lista = [] for n in nomi: # Se la prima lettera NON è 'a', allora aggiungi il nome if n[0].lower() != "a": nuova_lista.append(n.capitalize()) return nuova_lista

Test: ["anna", "marco", "luigi"] -> ["Marco", "Luigi"]

print(filtra_iniziale_a(["anna", "marco", "luigi"]))

12.2. Modify the function so that it also deletes all names ending in "o" anna, marco, luigi > Luig Clue: To refer to the final letter you can use index - def filtra_nomi_completo(nomi): nuova_lista = [] for n in nomi:

Condizione: non deve iniziare per 'a' E non deve finire per 'o'

if n[0].lower() != "a" and n[-1].lower() != "o": nuova_lista.append(n.capitalize()) return nuova_lista

Test: ["anna", "marco", "luigi"] -> ["Luigi"]

print(filtra_nomi_completo(["anna", "marco", "luigi"]))

Esercizi con gemini: esercizio 1: name=input(“insert name”) Birth_Year=int(input(“insert birth year”)) Age=2026-Birth_Year print (“hello” + name + “you are ” + str(Age) + “years old”) esercizio1: def check_shipping(amount): if amount >= 100: print(“the shipping cost is 0”) elif 50<=amount<100: print(“the shipping cost is 10”) else: print(“the shipping cost is 20”) check_shipping(33) esercizio2: def is_even(number): if number%2==0: return True else: return False print(is_even(4))

esercizio1: def guess(): i= word=input(“inserire la parola”) while word!= “exit” : word=input(“inserire di nuovo la parola”) i=i+ print(“parola indovinata”) print (“i tentativi sbagliati sono: ” +str( i )) SQL: select sum(giorniprenotati*costogiornaliero) as totbooking, appartamenti.città from appartamenti, tipo_appartamenti, prenotazioni, clienti where appartamenti.idappartamento=prenotazioni.idappartamento AND prenotazioni.idcliente=clienti.idcliente AND appartamenti.idappartamento=tipo_appartamenti.idtipo AND tipo_appartamenti.nometipo=’villa’ AND appartamenti.numeroletti>=3 AND clienti.nazionediresidenza=’’francia group by appartamenti.città having totbookins>= order by totbookings desc select nome , cognome, sum(giorniprenotati), idcliente from clienti, prenotazioni, appartamenti where clienti.idcliente=prenotazioni.idcliente AND appartamenti.idappartamento=prenotazioni.idappartamento AND appartamenti.numerostanze>=2 AND clienti.città=’londra’ group by idcliente , nome, cognome having sum(giorniprenotati)>=

Group by nome Having sum(prezzo_noleggiogiorni_durata) >= Order by sum(prezzo_noleggiogiorni_durata) cresc