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

Beto Carlos
Jul 21, 2017 · 4 min read
Credit: Christopher Gower

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?

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.

Beto Carlos

Some random thoughts from Beto Carlos. His journey in web development and design, along with his achievements and adventures.

)

Beto Carlos

Written by

Creative Development. Web development student @UVU. Currently enrolled in Full Stack Web Developer Nanodegree Program @udacity

Beto Carlos

Some random thoughts from Beto Carlos. His journey in web development and design, along with his achievements and adventures.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade