0% found this document useful (0 votes)
5 views4 pages

Python Alarm Clock Code Example

The document outlines the development of a Python alarm code utilizing classes, conditionals, and loops to enhance programming language usage in daily life. It emphasizes Python's ease of learning, extensive libraries, and applications in various fields, including artificial intelligence. The expected outcomes include a reliable, user-friendly alarm system that can be easily configured and integrated with other security devices.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Python Alarm Clock Code Example

The document outlines the development of a Python alarm code utilizing classes, conditionals, and loops to enhance programming language usage in daily life. It emphasizes Python's ease of learning, extensive libraries, and applications in various fields, including artificial intelligence. The expected outcomes include a reliable, user-friendly alarm system that can be easily configured and integrated with other security devices.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming 2022B

Coding an alarm in Python


Quishpe Vacacela, Toa Lucía1

1National Polytechnic School, Faculty of Mechanical Engineering, Quito, Ecuador

Resumen:Se elabora un código que indique la hora de alarma utilizando clases, condicionales y lazos de repetición.
This is aimed at optimizing the use of programming languages in everyday life. The Python program is used.
since it is an important programming language due to its ease of learning, wide range of libraries
and tools, portability, active community, applications in various industries and its popularity in intelligence
artificial and machine learning. It is recommended to develop this code on a device with automatic time setting since
Under that condition, the ties to be used will run. Once the alarm is generated, the expected results are the issuance of a
alarm signal at the desired moment, flexibility to configure the alarm, reliability in execution and a
user-friendly interface for the user.

Palabras clave: Lenguaje de programación, clases, bibliotecas, condicionales, lazos de repetición.

Coding an alarm in Python


Abstract: A code that indicates the alarm time is elaborated using classes, conditionals and repetition.
loops. This with the aim of optimizing the use of programming languages in everyday life. The Python
program is used as it is an important programming language due to its ease of learning, wide range of
libraries and tools, portability, active community, applications in various industries, and its popularity in
artificial intelligence and machine learning. It is recommended to create this code on a device with
automatic time, since under this condition the loops to be used will run. Once the alarm has been generated,
the expected results are the emission of an alarm signal at the desired time, flexibility to configure the
alarm, reliability in execution and a user-friendly user interface.
Keywords:Programming language, classes, libraries, conditionals, repetition loop

1. INTRODUCTION

Python is a high-level programming language that is used in a wide variety of applications.


debido a su simplicidad, flexibilidad y versatilidad. Aquí hay algunas razones por las que utilizar este
Language is important:

1. Easy to learn: Python is one of the easiest programming languages to learn. Its
syntax is readable and easy to understand, which makes it very accessible for those who are just
they begin to program.

2. Wide range of libraries and tools: Python has a large number of libraries and
tools that allow programmers to perform a wide range of tasks, from analysis
from data to artificial intelligence and machine learning.

3. Portability: Python runs on multiple platforms, including Windows, Mac, and Linux.
that makes it highly portable.

4. Active community: Python has an active community of developers who are


constantly improving the language and creating new tools and libraries.

5. Applications in various industries: Python is used in a wide range of applications, from


data analysis and data science to web programming and game development.
Programming 2022B

6. Applications in artificial intelligence and machine learning: Python is the language of


most popular programming for artificial intelligence and machine learning due to its
ease of use and the large number of libraries available for these fields.

CLASSES

In Python, a class is a programming structure that is used to define objects and their properties.
A class is used to define an object, but it is not the object itself. Instead, a class is like
a plan or a template to create objects.
In a class, the properties and methods of the object are defined. The properties are the variables that are
are used to store the object's data, while the methods are the functions that are used to
perform actions on the object.
Classes in Python are defined using the keyword 'class', followed by the class name and two
points. Within the class, properties and methods are defined using functions. By convention,
The name of the class starts with an uppercase letter.

CONDITIONALS
they are control structures that allow the flow of execution of a program to branch into different
directions, depending on one or more conditions that are evaluated as true or false. The
Conditionals allow the program to make decisions and act accordingly.

There are two types of conditionals in Python: the 'if' and the 'if-else'. The 'if' conditional is used when only
wants to check if a condition is true or false, while the 'if-else' conditional is used to
tomar diferentes acciones según si la condición es verdadera o falsa.

The basic syntax of the conditional 'if' in Python is as follows:

***
if condition:
Code that runs if the condition is true
***

2. METHODOLOGY

The following code was developed in the Phyton language:

***
import time

class Alarm:
def __init__(self, hour, minute): # Initialize hour and minute
of the alarm
[Link] = hora
[Link] = minute # The alarm is initialized off

self.alarma_encendida = False

def set_alarm(self, hour, minute): # Change the hour and the


alarm minute

[Link] = hora
[Link] = minuto # La alarma se apaga al cambiar la hora y
the minute

self.alarma_encendida = False
Programming 2022B

def turn_on_alarm(self): # Turn on the alarm

self.alarma_encendida = True

def turn_off_alarm(self): # Turn off the alarm

self.alarma_encendida = False

def check_alarm(self): # Check if the hour and the minute


current matches the hour and
the minute of the alarm and if the alarm
it is on

if [Link] == [Link]().tm_hour and [Link] ==


[Link]().tm_min and self.alarm_on:
If the conditions are met, sound the alarm and turn it off
print("Alarm sounding!")
self.turn_off_alarm()
else:
If the conditions are not met, indicate that the alarm
it is off or it is not the specified time
The alarm is off or it is not the specified time.

Create an instance of the Alarm class with specified hour and minute
mi_alarma = Alarma(7, 30)

Run the program in an infinite loop


while True:
Check the alarm every second
my_alarm.check_alarm()
[Link](1)

***

3. RESULTS AND DISCUSSION

Alarm signal emission: The main objective of a coded alarm in Python is to emit a signal.
of an alarm at a specific moment or when a condition is met. The expected result is that the
alarm sounds and alerts the user.

Flexibility: An alarm coded in Python should be flexible and customizable. This means that the
the user must be able to set the time and conditions for the alarm to sound, as well as the duration and the
type of alarm signal.

Reliability: An alarm coded in Python must be reliable and accurate. The expected outcome is that
the alarm rings at the exact scheduled time and works correctly without errors or problems.

User-friendly interface: The user must be able to interact with the alarm easily and
intuitive. Therefore, it is expected that the alarm will have a user-friendly interface that allows the user
easily configure and adjust the alarm settings.

4. CONCLUSIONES Y RECOMENDACIONES

The alarm must be efficient and reliable: it is important that the alarm is designed in such a way that it is
able to reliably detect and notify of any event that may be a threat to the
safety or the user's well-being. Additionally, the alarm must be designed to minimize the amount of
false alarms that occur, as this can be annoying and potentially dangerous.
Programming 2022B

The alarm must be easy to use and integrate: the alarm must be easy to set up and customize according to the
user needs and preferences. Furthermore, the alarm must be easy to integrate with other systems and
security devices, such as security cameras, motion sensors, and smart locks.

The alarm must be secure and tamper-resistant: the alarm must be designed to withstand tampering attempts.
or sabotage, such as signal inhibition or cable cutting. In addition, the alarm must be designed to
protect the user's privacy and prevent any type of intrusion or security breach.

The alarm must be scalable and adaptable: the alarm must be scalable and adaptable in order to be able to adapt to
the needs and changes of the user and the environment in which it is used. This includes the ability to add
and remove security devices as needed, and the ability to update the alarm software
to add new features or fix bugs.

REFERENCES

[1] Downey, A. (2012). Think Python: How to Think Like a Computer Scientist. O'Reilly Media.
[2] Géron, A. (2017). Hands-On Machine Learning with Scikit-Learn and TensorFlow: Concepts, Tools,
and Techniques to Build Intelligent Systems. O'Reilly Media. Martelli, A., Ravenscroft, A., & Ascher,
D. (2005). Python Cookbook (2nd ed.). O'Reilly Media.
[3] McKinney, W. (2018). Python for Data Analysis: Data Wrangling with Pandas, NumPy, and IPython
(2nd ed.). O'Reilly Media.
[4] Sweigart, A. (2015). Automate the Boring Stuff with Python: Practical Programming for Total
Beginners. No Starch Press.
Python 3 Reference Manual
Publishing Platform.

You might also like