0

I'm new to python. I tried different ways to add values to my code. In this code, I have 2 problem.

  • I need to use the input numbers (e.g 0400 or 0352) to add to the dictionary
  • convert the input numbers to time (e.g 4:00 or 3:52).
employee1_data = {};
    
def login_time_admin_a():  
        while True:
            print("""
            ==============================
            | PLEASE ENTER YOUR INFO     |
            ==============================
                """)
            time=input("ENTER TIME: ")
            if time.isalpha():
                print("""
                ======================
                | INCORRECT INPUT    |
                ======================
                """)
                continue
            date = input("ENTER DATE: ")
            if date.isalpha():
                print("""
                ======================
                |  INCORRECT INPUT   |
                ======================
                """)
                continue
            else:
                print("""
                    ============================
                    | THANK YOU FOR LOGGING IN |
                    ============================
                    """)
                employee1_data[time] = time()
                employee1_data[date] = date()
Jeon Lei
  • 11
  • 2
  • 1
    What exact problem do you face ? You can't input a string then "call" it with `time()` Seems the problem is NOT at all adding in dict, but converting frmo string to date – azro Jan 09 '22 at 09:49
  • Does this answer your question? [Convert string into datetime.time object](https://stackoverflow.com/questions/14295673/convert-string-into-datetime-time-object) – mkrieger1 Jan 09 '22 at 09:49

1 Answers1

0

According with the documenatation:

>>> employee1_data = {}
>>> employee1_data['this_key_001']='this_value_001'
>>> print(employee1_data['this_key_001'])
this_value_001
>>> employee1_data['use the input numbers']=int('0400')
>>> print(employee1_data['use the input numbers'])
400
>>> employee1_data['use the input numbers']=str('0400')
>>> print(employee1_data['use the input numbers'])
0400

You can use the same method for the time data or you can use a special format data or string ...

data = (1)
format_string = "Your current balance is $%s."
print(format_string % data)
...
Your current balance is $1.