Es. Python su numeri, stringhe, operatori aritmetici, operatori di confronto, input e output 2
Versione italiana
Esercizi
Esercizio 11: Calcolo del Perimetro di un Rettangolo
Chiedi all’utente di inserire la lunghezza e la larghezza di un rettangolo e calcola il perimetro.
Esercizio 12: Verifica di Un Numero Positivo
Chiedi all’utente di inserire un numero e stampa un messaggio che indica se il numero è positivo.
Esercizio 13: Ripetizione di una Stringa
Chiedi all’utente di inserire una stringa e un numero intero, e stampa la stringa ripetuta quel numero di volte.
Esercizio 14: Calcolo della Radice Quadrata
Chiedi all’utente di inserire un numero e calcola la sua radice quadrata.
Esercizio 15: Calcolo del Volume di un Cilindro
Chiedi all’utente di inserire il raggio e l’altezza di un cilindro e calcola il volume.
Esercizio 16: Controllo di Un Numero Negativo
Chiedi all’utente di inserire un numero e stampa un messaggio che indica se il numero è negativo.
Esercizio 17: Calcolo della Differenza
Chiedi all’utente di inserire due numeri e calcola la loro differenza.
Esercizio 18: Verifica di Un Numero Intero
Chiedi all’utente di inserire un numero e stampa un messaggio che indica se è un numero intero.
Esercizio 19: Calcolo dell’Esponenziale
Chiedi all’utente di inserire un numero e calcola l’esponenziale
(e^x) utilizzando la funzione math.exp()
.
Esercizio 20: Creazione di una Stringa in Maiuscolo
Chiedi all’utente di inserire una stringa e stampa la stringa in maiuscolo.
Soluzioni
Soluzione 11
= float(input("Inserisci la lunghezza del rettangolo: "))
lunghezza = float(input("Inserisci la larghezza del rettangolo: "))
larghezza = 2 * (lunghezza + larghezza)
perimetro print(f"Il perimetro del rettangolo è: {perimetro}")
Soluzione 12
= float(input("Inserisci un numero: "))
numero = "Il numero è positivo." * (numero > 0) + "Il numero non è positivo." * (numero <= 0)
positivo print(positivo)
Soluzione 13
= input("Inserisci una stringa: ")
stringa = int(input("Inserisci un numero intero: "))
ripetizioni = stringa * ripetizioni
risultato print(f"La stringa ripetuta è: {risultato}")
Soluzione 14
import math
= float(input("Inserisci un numero: "))
numero = math.sqrt(numero)
radice_quadrata print(f"La radice quadrata di {numero} è: {radice_quadrata}")
Soluzione 15
import math
= float(input("Inserisci il raggio del cilindro: "))
raggio = float(input("Inserisci l'altezza del cilindro: "))
altezza = math.pi * (raggio ** 2) * altezza
volume print(f"Il volume del cilindro è: {volume}")
Soluzione 16
= float(input("Inserisci un numero: "))
numero = "Il numero è negativo." * (numero < 0) + "Il numero non è negativo." * (numero >= 0)
negativo print(negativo)
Soluzione 17
= float(input("Inserisci il primo numero: "))
num1 = float(input("Inserisci il secondo numero: "))
num2 = num1 - num2
differenza print(f"La differenza è: {differenza}")
Soluzione 18
= input("Inserisci un numero: ")
numero = "È un numero intero." * numero.isdigit() + "Non è un numero intero." * (not numero.isdigit())
intero print(intero)
Soluzione 19
import math
= float(input("Inserisci un numero: "))
numero = math.exp(numero)
esponenziale print(f"L'esponenziale di {numero} è: {esponenziale}")
Soluzione 20
= input("Inserisci una stringa: ")
stringa = stringa.upper()
maiuscolo print(f"La stringa in maiuscolo è: {maiuscolo}")
Italian version
Exercises
Exercise 11: Calculating the Perimeter of a Rectangle
Ask the user to enter the length and width of a rectangle and calculate the perimeter.
Exercise 12: Verifying a Positive Number
Ask the user to enter a number and print a message indicating whether the number is positive.
Exercise 13: Repeating a String
Ask the user to enter a string and an integer, and print the string repeated that number of times.
Exercise 14: Calculating the Square Root
Ask the user to enter a number and calculate its square root.
Exercise 15: Calculating the Volume of a Cylinder
Ask the user to enter the radius and height of a cylinder and calculate the volume.
Exercise 16: Checking a Negative Number
Ask the user to enter a number and print a message indicating whether the number is negative.
Exercise 17: Calculating the Difference
Ask the user to enter two numbers and calculate their difference.
Exercise 18: Checking an Integer
Ask the user to enter a number and print a message indicating whether it is an integer.
Exercise 19: Calculating the Exponential
Ask the user to enter a number and calculate the exponential (e^x)
using the math.exp()
function.
Exercise 20: Creating a String in Uppercase
Ask the user to enter a string and print the string in uppercase.
Solutions
Solution 11
= float(input("Enter the length of the rectangle: "))
length = float(input("Enter the width of the rectangle: "))
width = 2 * (length + width)
perimeter print(f"The perimeter of the rectangle is: {perimeter}")
Solution 12
= float(input("Enter a number: "))
number = "The number is positive." * (number > 0) + "The number is not positive." * (number <= 0)
positive print(positive)
Solution 13
= input("Enter a string: ")
string = int(input("Enter an integer: "))
repetitions = string * repetitions
result print(f"The repeated string is: {result}")
Solution 14
import math
= float(input("Enter a number: "))
number = math.sqrt(number)
square_root print(f"The square root of {number} is: {square_root}")
Solution 15
import math
= float(input("Enter the radius of the cylinder: "))
radius = float(input("Enter the height of the cylinder: "))
height = math.pi * (radius ** 2) * height
volume print(f"The volume of the cylinder is: {volume}")
Solution 16
= float(input("Enter a number: "))
number = "The number is negative." * (number < 0) + "The number is not negative." * (number >= 0)
negative print(negative)
Solution 17
= float(input("Enter the first number: "))
num1 = float(input("Enter the second number: "))
num2 = num1 - num2
difference print(f"The difference is: {difference}")
Solution 18
= input("Enter a number: ")
number = "It is an integer." * number.isdigit() + "Not an integer." * (not number.isdigit())
integer print(integer)
Solution 19
import math
= float(input("Enter a number: "))
number = math.exp(number)
exponential print(f"The exponential of {number} is: {exponential}")
Solution 20
= input("Enter a string: ")
string = string.upper()
uppercase print(f"The uppercase string is: {uppercase}")
Commenti
Posta un commento