bluehost

Saturday, 30 September 2023

Creating An Alarm Clock Using Python

 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

React vs Angular; Front-End Web Development

Angular and React  are two of the most popular Javascript tools for front-end development. React is a Javascript created by Meta...