"""
The script manages numbers of type float with a time stamp,
stored in the dbm file called datenumbers.
The key is the number and the value for each key is a tuple,
with a time stamp and the value.
"""
import dbm
from time import ctime

DBNAME = 'datednumbers'
FILE = dbm.open(DBNAME, 'c')
print('Welcome to our dated numbers!')
ANS = input('-> type a to add, r to retrieve : ')
CNT = len(FILE)
if ANS == 'a':
    NBR = float(input('-> give a number : '))
    NOW = ctime()
    DATA = (NOW, NBR)
    FILE[str(CNT)] = str(DATA)   
    print('stored', DATA)
else:
    PROMPT = '-> enter a natural number < ' + f"{CNT}" + ' : '
    IDX = int(input(PROMPT))
    DATA = eval(FILE[str(IDX)])
    print(DATA[1], 'was stored on', DATA[0])
FILE.close()
