-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexo10.rb
24 lines (17 loc) · 829 Bytes
/
exo10.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'date'
# Fonction pour calculer l'âge et les jours écoulés depuis la naissance
def calculate_age_and_days(birth_date)
today = Date.today
birth_date = Date.parse(birth_date)
# Calculer l'âge en années
age_in_years = today.year - birth_date.year - ((today.month < birth_date.month) || (today.month == birth_date.month && today.day < birth_date.day) ? 1 : 0)
# Calculer le nombre de jours écoulés depuis la naissance
days_since_birth = (today - birth_date).to_i
return age_in_years, days_since_birth
end
# Exemple d'utilisation
print "Entrez la date de naissance (format : YYYY-MM-DD) : "
birth_date = gets.chomp
age_in_years, days_since_birth = calculate_age_and_days(birth_date)
puts "Âge en années : #{age_in_years}"
puts "Nombre de jours écoulés depuis la naissance : #{days_since_birth}"