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

Комментарии • 139

  • @janayascott7078
    @janayascott7078 Год назад +17

    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

    • @yagnikbose8973
      @yagnikbose8973 Год назад +3

      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.

  • @diegosantosmoto
    @diegosantosmoto Год назад +13

    I like so much this kind of project. It's nice to practice and see how it works

  • @shyne4283
    @shyne4283 Год назад +4

    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

  • @NiceChange
    @NiceChange Год назад +1

    Well that was fun Tim!!! Loved it!!!

  • @usamashami11
    @usamashami11 Год назад +2

    I'm enjoying these mini projects

  • @xujason4607
    @xujason4607 Год назад

    Amazing video ,tks Tim !

  • @philippedid
    @philippedid 6 месяцев назад

    Very nice tip as usual thank you TIM

  • @kipngetichabsalom9100
    @kipngetichabsalom9100 Год назад +2

    educative content tim,

  • @baloney_sandwich
    @baloney_sandwich Год назад

    good stuff Tim

  • @FallenAngelMMA
    @FallenAngelMMA 7 месяцев назад

    Thank you so much!

  • @KomischeZitrone
    @KomischeZitrone Год назад

    Thats a realy good Tutorial thx

  • @sauraabh
    @sauraabh Год назад +13

    Bring more of these small projects please

  • @rohitjain6429
    @rohitjain6429 Год назад +13

    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)

  • @greattobehere
    @greattobehere Год назад +2

    Great video.. please make some videos on API development using python as those are the buzz words nowdays

  • @user-bb7uw8st6s
    @user-bb7uw8st6s Год назад +5

    I would like to see you do videos for intermediate or cool medium projects

  • @thinkandquestion1305
    @thinkandquestion1305 4 месяца назад

    ❤ Thank you ❤

  • @maccleary9576
    @maccleary9576 Год назад

    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?

  • @scleroman4931
    @scleroman4931 Год назад +1

    🔥🔥

  • @SkyFly19853
    @SkyFly19853 Год назад +4

    That can be very useful for video game development...

  • @thebugcoder3391
    @thebugcoder3391 Год назад +1

    Could you make some tutorials like these for Go? There aren't a lot of good tutorials around :)

  • @williamdelatorre9991
    @williamdelatorre9991 Год назад +6

    For some reason my CLEAR_AND_RETURN = "\033[H" does not work, I am using windows 10 and python V3.11.

    • @papa_AI
      @papa_AI 2 месяца назад

      it is not compulsory that you use the exact same syntax as other, why not just make another without using this.

  • @NiceChange
    @NiceChange Год назад +1

    is there a front end for this?

  • @peterfargo6044
    @peterfargo6044 11 месяцев назад +5

    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.

  • @mddawid0323
    @mddawid0323 Год назад +17

    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?

    • @fichtensaft5149
      @fichtensaft5149 Год назад +2

      Yeh, would be great

    • @TechWithTim
      @TechWithTim  Год назад +16

      I actually have videos on this already. Look for my "System Design" 2 part series

    • @fichtensaft5149
      @fichtensaft5149 Год назад +5

      @@TechWithTim great, thank you! Gonna watch it

  • @pi._.
    @pi._. Год назад +5

    Won’t the alarm sound too late since it takes time for it to execute the lines of code between time.sleep(1)?

    • @zanus5591
      @zanus5591 Год назад

      Yes, even time.sleep() takes more than a second to execute. So the alarm will take visibly longer to take off in 1000+ seconds

  • @RandyIsDandy
    @RandyIsDandy Год назад +1

    Hey would you mind telling me how you get your text colors that exact way? I really like it

    • @josh5001
      @josh5001 Год назад

      He uses the in-built Monokai color theme

    • @RandyIsDandy
      @RandyIsDandy Год назад

      @@josh5001 Thank you man much apprecaited!

  • @Dabber7
    @Dabber7 Год назад

    please make more mini projects on python

  • @soe3717
    @soe3717 Год назад +8

    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.

    • @kreollosos3203
      @kreollosos3203 Год назад +1

      I got the same issue

    • @goldenfox1471
      @goldenfox1471 Год назад

      i am also facing the same problem

    • @dhrubajyotibhattacharjee6609
      @dhrubajyotibhattacharjee6609 Год назад +1

      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!)

    • @batuhanbayr7613
      @batuhanbayr7613 10 месяцев назад

      yes me to because we are windows users ı try to fix it but nothing helped @@kreollosos3203

  • @cgmania230
    @cgmania230 Год назад

    please make more mini projects bro

  • @pablozuta2402
    @pablozuta2402 Год назад +4

    guys if you are getting an error try using a .wav file for the sound

  • @dWn2T
    @dWn2T Год назад

    This looks very smart:
    "2 from playsound import playsound"
    I will write for myself...

  • @ssigitas69
    @ssigitas69 Год назад +3

    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??? 🤔

    • @Gigusx
      @Gigusx Год назад +1

      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.

    • @ssigitas69
      @ssigitas69 Год назад

      @@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

  • @raim_akhmetov
    @raim_akhmetov 4 месяца назад

    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🙏

  • @adityadua3009
    @adityadua3009 Год назад +1

    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?

  • @ericward284
    @ericward284 Год назад

    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?

  • @pranavireddy8221
    @pranavireddy8221 10 месяцев назад

    plz do more projects

  • @rashichauhan4501
    @rashichauhan4501 Год назад

    the alarm doesn't work even tho I installed playsound but still its showing error

  • @youssefsn
    @youssefsn Год назад +4

    Great mini project, but why not use divmod() function for time and the os module for clearing?

  • @spacechaser2843
    @spacechaser2843 Год назад

    Possible in idle

  • @batuhanbayr7613
    @batuhanbayr7613 10 месяцев назад

    how ı will do this as a windows user?

  • @aronds24
    @aronds24 Год назад

    Any alternative to clear_and_return?

    • @abdurrahmanbasil8473
      @abdurrahmanbasil8473 Год назад +1

      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)

  • @combogaming8302
    @combogaming8302 Год назад

    how to get this code

  • @tronicit
    @tronicit 8 месяцев назад

    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.

  • @saranshbalian4014
    @saranshbalian4014 4 месяца назад +1

    Bro , ANSI characters are not working in pycharm help me😢

  • @PriyansuPanda0220
    @PriyansuPanda0220 Месяц назад +1

    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........

  • @maverick4668
    @maverick4668 Год назад

    Can you sell this type of app?

  • @fargoretro
    @fargoretro Год назад +2

    Did not hear the sound.

  • @gjedda63
    @gjedda63 Год назад

    How do you know what to import?

    • @tranminhlong5192
      @tranminhlong5192 Год назад

      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

    • @truepvp5463
      @truepvp5463 Год назад

      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

  • @AliRaza-pr5tk
    @AliRaza-pr5tk Год назад

    I have a confusion in minutes left and seconds left ,that what are they doing ?

  • @GTV_367
    @GTV_367 Год назад

    🙌

  • @prashantraj5972
    @prashantraj5972 Год назад +2

    Its for beginners or intermediate?

    • @Lambyyy
      @Lambyyy Год назад +2

      Definitely beginner.

    • @Daviesdev
      @Daviesdev Год назад

      @@Lambyyy exactly

  • @moe9062
    @moe9062 Год назад +49

    We didn't hear any alarm though

    • @TechWithTim
      @TechWithTim  Год назад +18

      Ya I realized I didn’t have it enabled in my recording, it did work tho

    • @someguy2972
      @someguy2972 Год назад +14

      Ahh good, otherwise I'm deaf.

    • @yahyabzl1112
      @yahyabzl1112 Год назад +1

      how do we enable it

    • @Yellow_300
      @Yellow_300 5 месяцев назад

      import literally_the_whole_universe
      import everything_in_earth

  • @ssigitas69
    @ssigitas69 Год назад +1

    I don't know why, but escape sequences don't work for me 😥 anyway printing in new line...

  • @homieee_lander
    @homieee_lander 5 месяцев назад +1

    is it just me or did anyone else couldn't manage to intall the playsound module either? Mine simply wouldn't get installed.

  • @Snakyboopface-Tori
    @Snakyboopface-Tori 4 месяца назад

    I cant get the alarm to play it keeps giving me an error also I couldnt hear the alarm in the video

  • @JashSingh-bv5ge
    @JashSingh-bv5ge 10 месяцев назад

    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 ?

    • @dyashwanth9822
      @dyashwanth9822 8 месяцев назад

      its working fine for me on Terminal , try on terminal not on output

  • @itzAustin-qr8zx
    @itzAustin-qr8zx Год назад +1

    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

  • @learnomics
    @learnomics Год назад +2

    We did not heard the sound

  • @burstfireno1617
    @burstfireno1617 Год назад

    Pyto app for Ipad cant find this module 😫

  • @ziademad3287
    @ziademad3287 Год назад

    CLEAR_AND_RETURN not working

  • @praveenpcpc
    @praveenpcpc Год назад +1

    Pls make a video Python new version for beginner

  • @abdulazizkodirov5323
    @abdulazizkodirov5323 Год назад

    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.

  • @goldenfox1471
    @goldenfox1471 Год назад

    The CLEAR_AND_RETURN is not working. Can anyone help me plz?

    • @abdurrahmanbasil8473
      @abdurrahmanbasil8473 Год назад +2

      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)

  • @manan2007
    @manan2007 Год назад +1

    I followed the video and now I can't stop the alarm D:

  • @winningtech5
    @winningtech5 Год назад

    I thought we'll be using python scheduler

  • @pottoker612
    @pottoker612 Год назад

    would have made more sense to add a gui with tkinter and have user input...

  • @rachinter
    @rachinter Год назад

    Divmod and os modules are much easier.

  • @pottoker612
    @pottoker612 Год назад

    chat gpt can generate an alarm clock script in about 30 secs...

  • @atrophysicist
    @atrophysicist Год назад +3

    There was no actual alarm sound

  • @prudhvichinnam1488
    @prudhvichinnam1488 Год назад

    No it's not working

    • @prashantdas3618
      @prashantdas3618 Год назад

      tell me your email id I'll send you a simpler version of this programme

    • @rohitjain6429
      @rohitjain6429 Год назад

      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

  • @OmegaAftermath
    @OmegaAftermath 16 дней назад

    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)

  • @BravoSixGoingDark.
    @BravoSixGoingDark. Год назад

    Is there any python code that simulates beard growth?

  • @mayankvaswani100
    @mayankvaswani100 Год назад

    Bro forgot 60*2 = 120

    • @gaurangkhera
      @gaurangkhera Год назад

      Nah, floor division would return 2, so it was correct.

    • @truepvp5463
      @truepvp5463 Год назад

      // is how many times 60 could be contained in 120 not the devision FeelsDankMan

  • @ohhhbirdy5975
    @ohhhbirdy5975 Год назад

    yeah we didnt hear it LOL

  • @combogaming8302
    @combogaming8302 Год назад

    what is in alarm.mp3 file,tim is not explaining things clearly for the beginners

  • @abdenourhajy2006
    @abdenourhajy2006 7 месяцев назад

    Man you are Unlucky

  • @shomugger
    @shomugger 4 месяца назад

    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

  • @JNET_Reloaded
    @JNET_Reloaded Год назад

    nope hered nothing!

  • @prashantdas3618
    @prashantdas3618 Год назад

    for a shorter version, tell me your email id

  • @ssigitas69
    @ssigitas69 Год назад

    I don't know why, but escape sequences don't work for me 😥 anyway printing in new line...

    • @stevemorse5052
      @stevemorse5052 Год назад

      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.

    • @stevemorse5052
      @stevemorse5052 Год назад

      Just tried the program outside of PyCharm and I am getting the escape sequence's less the \033 printed out

    • @ssigitas69
      @ssigitas69 Год назад

      @@stevemorse5052 I'm using Windows 11 and Pycharm. First escape sequence doesn't clean terminal, second doesn't work as well

    • @stevemorse5052
      @stevemorse5052 Год назад

      @@ssigitas69 Hi did you read my second response above?
      The only thing I can think of is that PyCharm runs its own terminal.

    • @ssigitas69
      @ssigitas69 Год назад

      @@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