Reputation:
I'm trying to make a command line alarm clock application. The way it's supposed to work is that when the current hour and the current minute are the same as the hour and minute you want to wake up at, it will exit the while
loop and wake you up. However, when the hour and the minute are the same as the current it just keeps going. I've attempted to google for an answer but I haven't been able to find relevant information.
import sys
import datetime
a = 0
current_time = datetime.datetime.now()
print current_time.hour
print current_time.minute
wakehour = raw_input("When do you wanna wake up?\n What hour? Use the 24-hour clock.\n>>>")
wakeminute = raw_input("How many minutes after the hour?\n>>>")
print wakehour
print wakeminute
while a == 0:
current_time = datetime.datetime.now()
print current_time.hour
print current_time.minute
if current_time.hour == wakehour and current_time.minute == wakeminute:
print 'wakey wakey'
a = 1
Upvotes: 0
Views: 48
Reputation: 16556
When you ask a raw_input
the result is a string:
>>> a=raw_input()
1
>>> type(a)
<type 'str'>
But current_time.hour
is an int:
>>> current_time = datetime.datetime.now()
>>> type(current_time.hour)
<type 'int'>
So, try to convert wakehour
/wakeminute
to int before the conversion with int(wakehour)
Upvotes: 1