The function append does not add to my list, but rather changes the original
import datetime
from datetime import datetime
A = True
while True:
try:
if A == True:
input_user_bd = input('inter your barth day and your name(dd-mm-yyyy,the name):')
else:
input_user_bd = input('add your barth day and your name to the list '
'dd-mm-yyyy,the name)\nif you want to delete the list enter(clear):')
date,name = input_user_bd.split(',')
bd = datetime.strptime(date, '%d-%m-%Y')
break
except ValueError or AttributeError:
print('error')
def calculate_age(bd):
today = datetime.now()
return today.year - bd
calculate_age(bd.year)
def print_age(th_name,age):
print(th_name,'you are',age,"years old")
print_age(name,calculate_age(bd.year))
people = {
'the name':[],
'the date':[]
}
people['the name'].append(name)
people['the date'].append(date)
print(people)
A = False
if input_user_bd == 'clear':
break
The following are the command line inputs and outputs:
inter your barth day and your name(dd-mm-yyyy,the name):11-11-2001,a
a you are 22 years old
{'the name': ['a'], 'the date': ['11-11-2001']}
add your barth day and your name to the list dd-mm-yyyy,the name)
if you want to delete the list enter(clear):11-11-2001,AA
AA you are 22 years old
{'the name': ['AA'], 'the date': ['11-11-2001']}
add your barth day and your name to the list dd-mm-yyyy,the name)
if you want to delete the list enter(clear):
Comments
Post a Comment