Python Video Tutorial 1- Alarm Program

Words
375
Reading
2 min
Listen
Play
8y

python video tutorial2.jpg

What Will I Learn?

  • You will learn to write an alarm program in Python language
  • You will learn to use the "while" loops
  • You will learn to use 'if, elif and else' functions from conditional states
  • You will learn to use the 'time' library and the 'localtime' module
  • You will improve your algorithm ability when writing programs

Requirements

  • Python 3.6.5
  • Pycharm or another text editors (python idle)

Difficulty

  • Intermediate

Links

Codes

print("""******************

Alarm Program

******************""")

import time

Ahour = int(input("Please enter the alarm hour:"))
Aminute = int(input("Please enter the alarm minute:"))

while True:
    LT = time.localtime(time.time())
    if Ahour == LT.tm_hour and Aminute == LT.tm_min :
        print( "Time is:", LT.tm_hour, ":", LT.tm_min, "The alarm is ringing")
        break
    elif (LT.tm_min == 30 and LT.tm_sec ==1 ) or (LT.tm_min == 7 and LT.tm_sec ==1 ):
        rhour = Ahour - LT.tm_hour
        rminute= Aminute - LT.tm_min
        print( "Remaining to Alarm:", rhour, ":", rminute)
    else:
        pass

print (" The Alarm Has been terminated")



Description

In this lesson I will tell you how to write the Alarm application in Python language. We use the 'time' library when designing the alarm program algorithm. By using the 'locatime' module in this library, we instantly get the clock data of our computer into the program. The alarm starts by asking the user to enter the alarm time and minute. After this phase, we are beginning to test the alarm information that the user has entered in the 'while' loop. We check that the alarm clock entered in the test phase matches the local time of our computer. In this control phase we use 'if, elif and else' functions. You can see the details of these functions in the codes and videos we have done. We also learned not to get the duration of the alarm to be steady at certain intervals within the program. I hope that this content is useful for you.

Step -1

In the first step, we enter the name of our program and import the 'time' library
step1.PNG

Step -2

In the second step, we define our variables so that the user can enter the alarm time.

step2.PNG

Step -3

In the third step, we start the 'while' cycle according to the condition of 'True'.
step3.PNG

Step -4

In the fourth step, we set the conditions according to the alarm time that the user has entered and make sure that they are tested.
step-4.PNG

Step -5

In the fifth step, we complete the program by typing the expression indicating the end of our program.

step 5.PNG

Video Tutorial

Curriculum

  • This is the first part of the Python Video Tutorial Serie



Posted on Utopian.io - Rewarding Open Source Contributors