Python Code - Alarm Clock

Effcient python code for clock with alarm

Python Code

black flat screen computer monitor
black flat screen computer monitor

ChatGPT

Here's a concise and efficient Python code for a clock with an alarm:

python

Copy code

import datetime

import time

def set_alarm(alarm_time):

while True:

current_time = datetime.datetime.now().strftime("%H:%M:%S")

if current_time == alarm_time:

print("Alarm!")

break

time.sleep(1)

def main():

alarm_time = input("Enter the alarm time in HH:MM:SS format: ")

set_alarm(alarm_time)

if name == "__main__":

main()

Code Description

This code uses the datetime module to get the current time and compare it with the desired alarm time. It uses a while loop to continuously check the time until it matches the alarm time. The time.sleep(1) function is used to pause the execution for 1 second between each check, which helps in conserving CPU resources.

To use the code, simply run the main() function. It prompts the user to enter the alarm time in the HH:MM:SS format, and then it calls the set_alarm() function, which continuously checks the time until it matches the alarm time and prints "Alarm!".

You can customize the code further by adding additional functionality such as playing a sound or displaying a message when the alarm triggers.

gray concrete wall inside building
gray concrete wall inside building

Our mission

We're on a mission to change the way the housing market works. Rather than offering one service or another, we want to combine as many and make our clients' lives easy and carefree. Our goal is to match our clients with the perfect properties that fit their tastes, needs, and budgets.

Our vision

We want to live in a world where people can buy homes that match their needs rather than having to find a compromise and settle on the second-best option. That's why we take a lot of time and care in getting to know our clients from the moment they reach out to us and ask for our help.

white and black abstract painting
white and black abstract painting

Our team

Our strength lies in our individuality. Set up by Esther Bryce, the team strives to bring in the best talent in various fields, from architecture to interior design and sales.

woman wearing black scoop-neck long-sleeved shirt
woman wearing black scoop-neck long-sleeved shirt
Esther Bryce

Founder / Interior designer

woman in black blazer with brown hair
woman in black blazer with brown hair
Lianne Wilson

Broker

man standing near white wall
man standing near white wall
Jaden Smith

Architect

woman smiling wearing denim jacket
woman smiling wearing denim jacket
Jessica Kim

Photographer