Search code examples
pythonpython-3.9

How do I change the timestamp for each new input taken?


So I'm trying to make a program where the user inputs notes and it timestamps them, but when I run this all the date-times are the same. Is there any way I can change this?

from time import time, ctime
t = time()
noteno = int(input("How many notes would you like to add? "))
for i in range (noteno):
 note = input("Add note: ")
 stamp1 = ctime(t)
 print(f"Note stamped at: {stamp1}")

Solution

  • You can put the t=time() in for loop.

    from time import time, ctime
    noteno = int(input("How many notes would you like to add? "))
    for i in range (noteno):
        t = time()
        note = input("Add note: ")
        stamp1 = ctime(t)
        print(f"Note stamped at: {stamp1}")