Udacity Full Stack Developer Nanodegree Kick start and ‘Take a break’ Mini project.

Yesterday I started Udacity Full Stack Developer Nanodegree (FSDN, for short). So far, I’m really enjoying it, it’s easy to understand and their videos are fun.
Like I said in my previous post, writing on Medium was something that I wanted to do for a long time, but for some reason or another I didn’t do it. Now, I’m committed to do it, and what better place to start writing about, then this course I’m taking.
In our first course, the teacher walks us through a small project called ‘Take a break’, which is basically a python program, that opens a web browser with a youtube song, every 2 hours or whatever time we decide to program it.
This is the code for the program:
import timeimport webbrowserprint 'This program started on: ' + time.ctime()i = 1while i <= 3:time.sleep(10)webbrowser.open('https://www.youtube.com/watch?v=dQw4w9WgXcQ')i = i + 1
Really simple stuff right? So let’s break it down.
Importing necessary modules for the program to work
To access some capabilities of the python language, first we need to import these 2 modules from the Python Standard Library. These modules will give you access to handy functions in order to make the program work.
import timeimport webbrowser
To understand better these modules I made this graphic:

Once we run the program, we want to print, at what time the program started (just a handy feature).
Printing the local time
Now, we concatenate the ‘This program started on: ‘ with the function ctime , we invoke this function by writing first the module this function resides, following the function itself time.ctime() . This function returns the local time.
print 'This program started on: ' + time.ctime()Looping with while
Now we loop the program so it opens the web browser in a specified interval of time.
i = 1while i <= 3:time.sleep(10)webbrowser.open('https://www.youtube.com/watch?v=dQw4w9WgXcQ')i = i + 1
i = 1
First we define an integer which will define how many times we have actually run the program.
while i <= 3:
After that, we initialize the while loop. Basically this is telling that while the i is less or equals to 3 (this is how many breaks we want to take), the program can execute. If i is more than 3 the program exits out of the while loop and finishes the program.
time.sleep(10)
After the condition has been met (i is less or equal than 3), we tell our program to wait (in this example I used 10 seconds). We do this by invoking the .sleep function in the time module. And we pass an integer (seconds) on how much time we want the program to wait.
When the program has waited, whatever seconds we passed, now it will execute our next line of code.
webbrowser.open('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
This snippet of code will open the browser in whatever website we decided. Again we do this by invoking the .open function in the webbrowser module and passing whatever link we want the browser to open. In this case a classic:
i = i + 1
After it opens the browser to the link that we wanted, we need to let know the program, that he already did it once, so we add 1 to i.
Now, the program will loop 3 times, until i becomes 4 and the while condition is no longer true.
So, what did I learn?
- I learned how the Python Standard Library is structured and how can I access to cool functions, my programs can do.
- I learned the definition of abstraction, which basically is how we assign names to define processes, things etc. Take for instance the
.sleepfunction, we know what it does, and we know that is inside thetimemodule in the Python Standard Library, but we probably don’t know out of the box, how it does it. That’s why we have documentation we can go and reference it. - The importance of while loops. Programs are always doing and re-doing processes, while loops let us define how long will the program will run the process and when to exit it.
Wooow. I wrote a lot for just a little program. Anyways it help me understand some key concepts in programming. By any means I’m an expert so if there’s a mistake in what I wrote, let me know and I’ll fix it.

