Berechnen des Alters in PythonPython

Python-Programme
Anonymous
 Berechnen des Alters in Python

Post by Anonymous »

Ich versuche, einen Code zu erstellen, in dem der Benutzer nach seinem Geburtsdatum und dem heutigen Datum gefragt wird, um sein Alter zu bestimmen. Was ich bisher geschrieben habe, ist:

Code: Select all

print("Your date of birth (mm dd yyyy)")
Date_of_birth = input("--->")

print("Today's date: (mm dd yyyy)")
Todays_date = input("--->")

from datetime import date
def calculate_age(born):
today = date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))

age = calculate_age(Date_of_birth)
Allerdings läuft es nicht so, wie ich es mir erhofft hätte. Könnte mir jemand erklären, was ich falsch mache?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post