Ask coding questions

← Back to all posts
repeat help
theopythontest (0)

i have some code. ignore the indentation and any errors in the code. it works. how do i make it so if i put in anything other then time (weather for example) it then shows what i asked for. currently anything that isnt time will print the time. how do i get this to repeat. if i copy the code to underneath itself then i am forced to type in time and cant type anything else.

print("")
cmd = input("Enter Command ")
if cmd == "time" or "date":
#DATE TIME SCRIPT

import time
import calendar

This will make the program sleep for the specified amount of seconds

time.sleep(1)

From seconds since epoch to utc time

epochtoutc = time.gmtime()

From seconds since epoch to local time

epochtolocal = time.localtime()

From utc time to seconds since epoch

utctoepoch = calendar.timegm(epochtoutc)

From utc time to seconds since epoch

localtoepoch = time.mktime(epochtolocal)
#time and date(shortened)
print(time.asctime(epochtolocal))
print("")
else:
print("Unknown Command")

Comments
hotnewtop
Bookie0 (6263)

Please include a repl.

Also, if you want to check if the user said "time" or "date", you have to change your conditional from:

if cmd == "time" or "date":

To:

if cmd == "time" or cmd == "date":

But you seem to want to make the program do different things depending on if the user wants the date or the time. So what you can do is just check if the user typed "time" with if cmd == "time":, and then use an elif statement: elif cmd == "date:".

You can then put the respective code underneath each of those conditional blocks.

Let me know if you have any other questions.

Good luck! :D

OldWizard209 (1521)

Can you please attach the repl? This is very hard to follow...