This code uses the datetime
module to get the current time and the input()
function to get the desired alarm time from the user. The while
loop continuously checks if the current time matches the alarm time. If it does, then it raises an alarm by printing “Alarm Raised” and exits the loop. Otherwise, it prints “Alarm Not Raised” and exits the loop.
import datetime
print(datetime.datetime.today().strftime("%H"))
print(datetime.datetime.today().strftime("%M"))
hour = int(input("Enter an hour: 15"))
minute = int(input("Enter a minute:53 "))
while True:
if hour == int(datetime.datetime.today().strftime("%H")) and minute == int(datetime.datetime.today().strftime("%M")):
print("Alarm Raised")
break
else:
print("Alarm Not Raised")
break
No comments:
Post a Comment