Mini Python Project Tutorial - Alarm Clock
HTML-код
- Опубликовано: 3 авг 2024
- Today, I'll be walking you through a mini-python project, where we will create an alarm clock/timer. This straightforward course will show you how to play sound and how you can create a FANCY thing with the terminal!
💻 Master Blockchain and Web 3.0 development today by using BlockchainExpert: algoexpert.io/blockchain - use code "tim" for a discount!
💻 ProgrammingExpert is the best platform to learn how to code and become a software engineer as fast as possible! programmingexpert.io/tim - use code "tim" for a discount!
💻Download Sound Effects: www.fesliyanstudios.com/royal...
💻Python Project Idea Blog: hackr.io/blog/python-projects
💻Fix Pip (Windows): • How to Install Pygame ...
💻Fix Pip (Mac): • How to Install Pygame ...
⭐️ Timestamps ⭐️
00:00 | Project Overview
01:12 | Project Setup
02:40 | Project Walkthrough
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
👕 Merchandise: teespring.com/stores/tech-wit...
📸 Instagram: / tech_with_tim
📱 Twitter: / techwithtimm
⭐ Discord: / discord
📝 LinkedIn: / tim-ruscica-82631b179
🌎 Website: techwithtim.net
📂 GitHub: github.com/techwithtim
🔊 Podcast: anchor.fm/tech-with-tim
🎬 My RUclips Gear: www.techwithtim.net/gear/
💵 One-Time Donations: www.paypal.com/donate?hosted_...
💰 Patreon: / techwithtim
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
⭐️ Tags ⭐️
- Tech With Tim
- Python Development
- Coding
⭐️ Hashtags ⭐️
#techwithtim #developer #python #howtolearncoding
I'm very new to python and just came from the password generator mini project video and was searching for more. Please do more and put them in a playlist. I was told the best way to learn python is to do mini projects and build your skill from there. These are so simple and you explain it so well as we follow along. Thank you so much for doing these! Please keep it up :D
Same here. I've only done python basics in data structures and several different kinds of programs but not really in terms of utilising software such as alarm clock etc. This is how I'm gaining experience with it.
I like so much this kind of project. It's nice to practice and see how it works
it took me 3 hours to figure out. Thank you so much. I am just a beginner.This veido helped me alot.I need that kind of easy projects to upgrade my python level
Well that was fun Tim!!! Loved it!!!
I'm enjoying these mini projects
Amazing video ,tks Tim !
Very nice tip as usual thank you TIM
educative content tim,
good stuff Tim
Thank you so much!
Thats a realy good Tutorial thx
Bring more of these small projects please
Alternative:
import time
def alarm(secs):
for x in range(secs,-1,-1):
minutes, seconds = divmod(x,60)
print(f"
{minutes:02d}:{seconds:02d}",end="")
time.sleep(1)
print("Time Up!")
alarm(5)
nice bro
👍
Great video.. please make some videos on API development using python as those are the buzz words nowdays
I would like to see you do videos for intermediate or cool medium projects
❤ Thank you ❤
Hi I am having trouble with getting the print statement to occur in the same line. I coded up the program exactly as you did and instead it still prints on a new line. Could I please have some help?
🔥🔥
That can be very useful for video game development...
yep! Definitely
@@Andrew-Tsegaye
Indeed!
Could you make some tutorials like these for Go? There aren't a lot of good tutorials around :)
For some reason my CLEAR_AND_RETURN = "\033[H" does not work, I am using windows 10 and python V3.11.
it is not compulsory that you use the exact same syntax as other, why not just make another without using this.
is there a front end for this?
if anyone has an error with getting "playsound" to install, namely:
"note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output."
try opening cmd and running
pip install --upgrade wheel
Then try to run:
pip install playsound
it fixed my issue.
Thanks
can you write the full process? it will be helpful for me
Can you do a video about strucurization of bigger python projects? Where to put the classes, how to enclose helper functions into packages, how to properly name your files?
Yeh, would be great
I actually have videos on this already. Look for my "System Design" 2 part series
@@TechWithTim great, thank you! Gonna watch it
Won’t the alarm sound too late since it takes time for it to execute the lines of code between time.sleep(1)?
Yes, even time.sleep() takes more than a second to execute. So the alarm will take visibly longer to take off in 1000+ seconds
Hey would you mind telling me how you get your text colors that exact way? I really like it
He uses the in-built Monokai color theme
@@josh5001 Thank you man much apprecaited!
please make more mini projects on python
It didn't work for me, though I did as 10:24 CLEAR_AND_RETURN the code remained exactly equal. keep as a colum of numbers
the run keeps like:
Alarm Will be sound in: 00:04
Alarm Will be sound in: 00:03
Alarm Will be sound in: 00:02
Alarm Will be sound in: 00:01
Alarm Will be sound in: 00:00
can you help me pls? The code is exactly the same.
I got the same issue
i am also facing the same problem
Although I am not well-informed about the issue, I think the special escape sequence "\033[H" is a terminal control code. As such, you would need to run the program on a terminal only to get the desired output. (Feel free to correct me if I am wrong!)
yes me to because we are windows users ı try to fix it but nothing helped @@kreollosos3203
please make more mini projects bro
guys if you are getting an error try using a .wav file for the sound
This looks very smart:
"2 from playsound import playsound"
I will write for myself...
ok
I like this small projects. You can see how in practise use function, loops, etc 🤗 But what I still can not understand, in what sequence code must be written? It's looks for me, input should be above def alarm() function. I still can not understand what should be where??? 🤔
Any specific code you have problem with? Generally, you write code in the order that it will be executed, which is from top to bottom. If you have e.g. variables that depend on other variables then you'll have to put them in order that makes sense, as in you can't define variables that other things depend on at the end of the file. All synchronous code (which everyone starts with when they learn to program) follows this flow.
/edit as for the input being below def alarm(), it's because "def alarm()" is the function *definition*. When you define a function you only create it but don't run it immediately. The function is run at the line "alarm(total_seconds)" and you ask the user for input before that happens.
@@Gigusx thank you so much 😊 I need to see many more projects to understand this. Because when I am learning about loops with users inputs (Sololearn, W3School) they teaches me first going input after while, for loops and conditionals if input blablabla, print this, else, print this
Hello, can you help me add an alarm (to the hourly alarm)? In my first year I was given a coursework and I am an aspiring programmer🙏
I was testing the code and arrived at a breaking point for it. Let's say you input 100 in minutes and 2 in seconds. Instead of showing 99:59 after 3 seconds, it shows 99:590, and so on. Is it possible to fix it, and if there is, could you please explain how?
Teleqram me 👆⬆️…
Hi! Mt ansi code for the clear and return doesn't work, and I definitely have "\033[H" for the value. Is there another one that I can use if this one isn't working?
Teleqram me 👆⬆️…
Same issue
same issue as well.
plz do more projects
the alarm doesn't work even tho I installed playsound but still its showing error
Great mini project, but why not use divmod() function for time and the os module for clearing?
Very true bro
Possible in idle
how ı will do this as a windows user?
Any alternative to clear_and_return?
import time
def clear_console():
# Print a sufficient number of empty lines to "clear" the console
print("
" * 50)
def alarm(seconds):
time_elapsed = 0
clear_console()
while time_elapsed < seconds:
time.sleep(1)
time_elapsed += 1
time_left = seconds - time_elapsed
minutes_left = time_left // 60
seconds_left = time_left % 60
clear_console()
print(f"{minutes_left:02d}:{seconds_left:02d}")
alarm(10)
how to get this code
I had a terrible time getting playsound to work on Python 3.11 (since updated to 3.12). What worked was installing playsound & PyObjC via pycharm. I couldn't install playsound via the terminal in OS X at all no matter what syntax I used. Hope this helps someone.
EDIT/Update: Also CLEAR_AND_RETURN didn't work as per other user posts below.
EDIT2/Update: the script works in the terminal but not directly in an IDE as the clear command CLEAR_AND_RETURN = "\033[H" only works in a shell.
Bro , ANSI characters are not working in pycharm help me😢
for those getting error at CLEAR_AND_RETURN part, replace your print statement with this-
print(f"
{minutes_left:02d}:{seconds_left:02d}", end='', flush=True)
hope this helps........
Can you sell this type of app?
Did not hear the sound.
How do you know what to import?
For an expert like him, he probably knows due to his experience in this field. For beginners, u have to do research to gain exp
an import is an already premade working snippet of code that u can put into ur code so u can use it aswell instead of having to make it on ur own from scratch, if u ever need something like camera tracking, voice or whatever just look it up and u will find a library that u can download thru pip/pip3, in the video he used the library playsound (which would take a long time to make on ur own) and directly used it in his code
I have a confusion in minutes left and seconds left ,that what are they doing ?
🙌
Its for beginners or intermediate?
Definitely beginner.
@@Lambyyy exactly
We didn't hear any alarm though
Ya I realized I didn’t have it enabled in my recording, it did work tho
Ahh good, otherwise I'm deaf.
how do we enable it
import literally_the_whole_universe
import everything_in_earth
I don't know why, but escape sequences don't work for me 😥 anyway printing in new line...
Not working for me either.
is it just me or did anyone else couldn't manage to intall the playsound module either? Mine simply wouldn't get installed.
I cant get the alarm to play it keeps giving me an error also I couldnt hear the alarm in the video
Im facing a problem the code is exact same, but im getting in this kind of output
in Terminal --> 00:03
00:02
00:01
00:00
can you Help me out ?
its working fine for me on Terminal , try on terminal not on output
Please I learnt and understood many syntax in python
But I want to know if I should know all the syntax and if I should memorize them cause, cause time to time I forget some of the syntax
If anyone has any cheat they use please share
Teleqram me 👆⬆️…
We did not heard the sound
Pyto app for Ipad cant find this module 😫
Teleqram me 👆⬆️…
CLEAR_AND_RETURN not working
Pls make a video Python new version for beginner
Teleqram me 👆⬆️…
Alarm didnt sound for me. I belive you need to provide the full path for playsound otherwise it wont work. I've had that problem a lot.
Teleqram me 👆⬆️…
The CLEAR_AND_RETURN is not working. Can anyone help me plz?
import time
def clear_console():
# Print a sufficient number of empty lines to "clear" the console
print("
" * 50)
def alarm(seconds):
time_elapsed = 0
clear_console()
while time_elapsed < seconds:
time.sleep(1)
time_elapsed += 1
time_left = seconds - time_elapsed
minutes_left = time_left // 60
seconds_left = time_left % 60
clear_console()
print(f"{minutes_left:02d}:{seconds_left:02d}")
alarm(10)
I followed the video and now I can't stop the alarm D:
I thought we'll be using python scheduler
would have made more sense to add a gui with tkinter and have user input...
Teleqram me 👆⬆️…😊
Divmod and os modules are much easier.
Teleqram me 👆⬆️…
chat gpt can generate an alarm clock script in about 30 secs...
Teleqram me 👆⬆️….
There was no actual alarm sound
No it's not working
tell me your email id I'll send you a simpler version of this programme
If you're talking ANSI characters to delete lines , yes they don't work everywhere, vs code works but run it windows terminal you'll get error
debugged with llama3-70b, issue with playsound fix was pip install for pygame for mp3
import time
import pygame
Clear = "\033[2J"
Clear_and_return = "\033[H"
def alarm(seconds):
time_elapsed = 0
print(Clear)
while time_elapsed < seconds:
time.sleep(1)
time_elapsed += 1
time_left = seconds - time_elapsed
minutes_left = time_left // 60
seconds_left = time_left % 60
print(f"{Clear_and_return}{minutes_left:02d}:{seconds_left:02d} Alarm will sound in ")
# Play the alarm sound
pygame.mixer.init()
pygame.mixer.music.load("soundcheck.mp3")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
time.sleep(0.1)
minutes = int(input("How many minutes to wait: "))
seconds = int(input("How many seconds to wait: "))
total_seconds = minutes * 60 + seconds
alarm(total_seconds)
Is there any python code that simulates beard growth?
Bro forgot 60*2 = 120
Nah, floor division would return 2, so it was correct.
// is how many times 60 could be contained in 120 not the devision FeelsDankMan
yeah we didnt hear it LOL
what is in alarm.mp3 file,tim is not explaining things clearly for the beginners
Man you are Unlucky
still struggle setting up "playsound". BTW can you make tutorial about python environment. Versions and how to store versions correct way, togeather with scripts or make it global?
It's very confusing for newcomers
Upd: problem with alarm.mp3 was in that track I downloaded from site provided) I changed track with mine and everything is working) Also I downgrade playsound to version 1.2.2
nope hered nothing!
for a shorter version, tell me your email id
I don't know why, but escape sequences don't work for me 😥 anyway printing in new line...
I am having the same problem.
@ssigitas69, what OS are you using. I am using Window10, with PyCharm
Tim, HELP!
It has been 30+ years since I have had to use ANSI escape sequence's.
Just tried the program outside of PyCharm and I am getting the escape sequence's less the \033 printed out
@@stevemorse5052 I'm using Windows 11 and Pycharm. First escape sequence doesn't clean terminal, second doesn't work as well
@@ssigitas69 Hi did you read my second response above?
The only thing I can think of is that PyCharm runs its own terminal.
@@stevemorse5052 yes mate, I read it. But maybe lack of my English, I didn't proper understand what you mean. But yes, maybe problem with Pycharm... I gonna try VScode later. Thank so much