Dec-21-2019, 02:27 AM
(This post was last modified: Dec-21-2019, 02:29 AM by ichabod801.)
I would like to simplify the following code, replacing the multiple if/elif's with a single line, but I have not been able to successfully figure it out.
def print_time(): now = datetime.datetime.now() hour = now.hour minute = now.minute second = now.second if hour == 1: command = 'echo 0 | fbink -i 1.png -g x=100 -c' elif hour == 2: command = 'echo 0 | fbink -i 2.png -g x=100 -c' elif hour == 3: command = 'echo 0 | fbink -i 3.png -g x=100 -c' elif hour == 4: command = 'echo 0 | fbink -i 4.png -g x=100 -c' elif hour == 5: command = 'echo 0 | fbink -i 5.png -g x=100 -c' elif hour ==6: command = 'echo 0 | fbink -i 6.png -g x=100 -c' # etc... os.system(command)Any help is much appreciated!