Objective:
This article describes how to create a simple alarm with Python, it can run at the command line terminal, it takes minutes as command-line arguments, the "wake-up" message is printed this minute, and the bell alarms, you can test it in 0 minutes, it will execute immediately, Use the Speaker Control Panel to adjust the sound.
Here's the script:
# alarm_clock.py # description:a Simple Python, the computer Act # like a alarm clock. Start it running from "command line" # with a command line argument specifying the duration in minutes # after which T o Sound the alarm. It'll sleep for this long, # and then beep a few times.
Use a duration of 0 to test the # alarm immediiately, e.g. for checking this volume is okay. # author:vasudev ram-http://www.dancingbison.com Import sys import string from time import sleep sa = sys.argv LSA = Len (SYS.ARGV) if LSA!= 2:print "Usage: [Python] alarm_clock.py duration_in_minutes" print "Example: [Python] A
larm_clock.py "Print" use a value of 0 minutes for testing the alarm immediately.
Print "Beeps a few times after the duration are over."
Print "Press Ctrl-c to terminate the alarm clock early." Sys.exit (1) try:minutes = Int (sa[1]) except Valueerror:print "Invalid numeric value (%s) for minutes"% sa[1] pr int "Should is an intEger >= 0 "sys.exit (1) If minutes < 0:print" Invalid value for minutes, should is >= 0 "sys.exit (1) SE
Conds = minutes * if minutes = = 1:unit_word = "Minute" Else:unit_word = "minutes" Try:if minutes > 0: print ' Sleeping for ' + str (minutes) + Unit_word sleep (seconds) print ' Wake up ' for I in Range (5): Print Chr (7), sleep (1) except Keyboardinterrupt:print "interrupted by user" Sys.exit (1) # EOF
Summarize:
This script I work already in use, very practical, of course, to avoid affecting other colleagues work, you'd better bring headphones, if the request is not high, in fact, printed from the terminal "wake-up" message is enough to remind. The above is the entire content of this article, I hope that the study and work can bring some help, if you have questions you can message exchange. Thank you for your support to the cloud-dwelling community.