Voici les solutions en Python pour chaque exercice demandé :
### Exercice 1
Ce programme calcule et affiche le montant augmenté des intérêts pour les `n`
années à venir.
```python
def calculate_savings(principal, annual_rate, years):
for year in range(1, years + 1):
amount = principal * (1 + annual_rate / 100) ** year
print(f"Year {year}: {amount:.2f}")
# Exemple d'utilisation
principal_amount = float(input("Enter the amount to save: "))
annual_interest_rate = float(input("Enter the annual interest rate (in %): "))
number_of_years = int(input("Enter the number of years: "))
calculate_savings(principal_amount, annual_interest_rate, number_of_years)
```
### Exercice 2
Ce programme calcule l’impôt sur le bénéfice d’une société selon les règles
données.
```python
def calculate_tax(profit):
if profit < 10000:
return profit * 0.20
elif profit <= 15000:
return 2000 + (profit - 10000) * 0.25
else:
return 3000 + (profit - 15000) * 0.30
# Exemple d'utilisation
profit_amount = float(input("Enter the profit amount (in USD): "))
tax_amount = calculate_tax(profit_amount)
print(f"The tax amount is: {tax_amount:.2f} USD")
```
### Exercice 3
Les fonctions calculant le volume d’une sphère et le cube d’un nombre.
```python
import math
def vols1(r):
return (4/3) * [Link] * (r ** 3)
def cube(x):
return x ** 3
def vols2(r):
return (4/3) * [Link] * cube(r)
# Exemple d'utilisation
radius = float(input("Enter the radius of the sphere: "))
print(f"Volume of the sphere (vols1): {vols1(radius):.2f}")
print(f"Volume of the sphere (vols2): {vols2(radius):.2f}")
```
### Exercice 4
Cette fonction calcule la valeur du nombre triangulaire d’indice `n`.
```python
def triangle(n):
return n * (n + 1) // 2
# Exemple d'utilisation
n = int(input("Enter the index n: "))
print(f"The triangular number of index {n} is: {triangle(n)}")
```
### Exercice 5
Les fonctions et script pour déterminer les nombres d’Armstrong.
```python
def somme_cubes_chiffres(n):
return sum(int(digit) ** 3 for digit in str(n))
def find_armstrong_numbers(limit):
armstrong_numbers = []
for number in range(limit):
if number == somme_cubes_chiffres(number):
armstrong_numbers.append(number)
return armstrong_numbers
# Exemple d'utilisation
limit = 10000
armstrong_numbers = find_armstrong_numbers(limit)
print(f"Armstrong numbers less than {limit}: {armstrong_numbers}")
```
Ces codes fournissent des solutions complètes pour chaque exercice, et vous pouvez
les exécuter facilement pour vérifier les résultats.