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
lunghezza = float(input("Inserisci la lunghezza del rettangolo: "))
larghezza = float(input("Inserisci la larghezza del rettangolo: "))
perimetro = 2 * (lunghezza + larghezza)
print(f"Il perimetro del rettangolo è: {perimetro}")Soluzione 12
numero = float(input("Inserisci un numero: "))
positivo = "Il numero è positivo." * (numero > 0) + "Il numero non è positivo." * (numero <= 0)
print(positivo)Soluzione 13
stringa = input("Inserisci una stringa: ")
ripetizioni = int(input("Inserisci un numero intero: "))
risultato = stringa * ripetizioni
print(f"La stringa ripetuta è: {risultato}")Soluzione 14
import math
numero = float(input("Inserisci un numero: "))
radice_quadrata = math.sqrt(numero)
print(f"La radice quadrata di {numero} è: {radice_quadrata}")Soluzione 15
import math
raggio = float(input("Inserisci il raggio del cilindro: "))
altezza = float(input("Inserisci l'altezza del cilindro: "))
volume = math.pi * (raggio ** 2) * altezza
print(f"Il volume del cilindro è: {volume}")Soluzione 16
numero = float(input("Inserisci un numero: "))
negativo = "Il numero è negativo." * (numero < 0) + "Il numero non è negativo." * (numero >= 0)
print(negativo)Soluzione 17
num1 = float(input("Inserisci il primo numero: "))
num2 = float(input("Inserisci il secondo numero: "))
differenza = num1 - num2
print(f"La differenza è: {differenza}")Soluzione 18
numero = input("Inserisci un numero: ")
intero = "È un numero intero." * numero.isdigit() + "Non è un numero intero." * (not numero.isdigit())
print(intero)Soluzione 19
import math
numero = float(input("Inserisci un numero: "))
esponenziale = math.exp(numero)
print(f"L'esponenziale di {numero} è: {esponenziale}")Soluzione 20
stringa = input("Inserisci una stringa: ")
maiuscolo = stringa.upper()
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
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
perimeter = 2 * (length + width)
print(f"The perimeter of the rectangle is: {perimeter}")Solution 12
number = float(input("Enter a number: "))
positive = "The number is positive." * (number > 0) + "The number is not positive." * (number <= 0)
print(positive)Solution 13
string = input("Enter a string: ")
repetitions = int(input("Enter an integer: "))
result = string * repetitions
print(f"The repeated string is: {result}")Solution 14
import math
number = float(input("Enter a number: "))
square_root = math.sqrt(number)
print(f"The square root of {number} is: {square_root}")Solution 15
import math
radius = float(input("Enter the radius of the cylinder: "))
height = float(input("Enter the height of the cylinder: "))
volume = math.pi * (radius ** 2) * height
print(f"The volume of the cylinder is: {volume}")Solution 16
number = float(input("Enter a number: "))
negative = "The number is negative." * (number < 0) + "The number is not negative." * (number >= 0)
print(negative)Solution 17
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
difference = num1 - num2
print(f"The difference is: {difference}")Solution 18
number = input("Enter a number: ")
integer = "It is an integer." * number.isdigit() + "Not an integer." * (not number.isdigit())
print(integer)Solution 19
import math
number = float(input("Enter a number: "))
exponential = math.exp(number)
print(f"The exponential of {number} is: {exponential}")Solution 20
string = input("Enter a string: ")
uppercase = string.upper()
print(f"The uppercase string is: {uppercase}")
Commenti
Posta un commento