I am currently trying to write a simple countdowntimer. But if I take for example 10 hours
as an input the if statement for the minutes is still being triggered instead of the if statement for the hours. Because of this the code errors out like this:
Traceback (most recent call last):
File "clock.py", line 29, in <module>
timer.timer(test_input)
File "clock.py", line 6, in timer
nt = int(nt)
ValueError: invalid literal for int() with base 10: '10 hours'
I think that this error message is not necessary to solve this problem because you can see very clearly that this error is caused because the wrong if statement is being triggered.
This is my code:
import time
class timer():
def timer(test_input):
if 'minutes' or 'minute' in test_input:
nt = test_input.replace('minutes','').replace('minute','')
nt = int(nt)
nt = int(nt*60)
print(nt)
while nt:
mins, secs = divmod(nt, 60)
timer = '{:02d}:{:02d}'.format(mins, secs)
print(timer, end="\r")
time.sleep(1)
nt -= 1
elif 'hours' or 'hour' in test_input:
nt = test_input.replace('hours','').replace('hour','')
nt = int(nt)
nt = int(nt*3600)
print(nt)
while nt:
mins, secs = divmod(nt, 60)
timer = '{:02d}:{:02d}'.format(mins, secs)
print(timer, end="\r")
time.sleep(1)
nt -= 1
print('ALARM')
test_input = input('give me an input for your countdown: ')
timer.timer(test_input)
Am I doing something wrong in my code? If so I would be very glad if someone could explain to me what I've made wrong and how I can fix this problem.
Thank's for every help and suggestion in advance:)
PS: Feel free to question if you don't understand something of my code.