Coding 101 18 (Transcript)


Download and watch the episode here:
Coding 101 18

Shannon Morse: Today on Coding 101 we are going to review tubbles, or tibbles? And we’re checking out functions. Get ready.

Netcasts you love, from people you trust. This is TWiT! Bandwidth for Coding 101 is provided by Cache Fly. At C-A-C-H-E-F-L-Y.com

This episode of Coding 101 is brought to you by Squarespace, the all in one platform that makes it fast and easy to create your own professional website or online portfolio. For a free 2 week trial and 10% off go to squarespace.com and use the offer code CODING. And by ShutterStock.com. With over 35 million high quality stock photos, illustrations, vectors and video clips, Shutterstock helps you take your creative projects to the next level. For 20% off your new account go to shutterstock.com and use the offer code CODING514.

Fr. Robert Ballecer: Welcome to Coding 101, it’s the show where snubs just knocked off her pack and also where we, oh that’s a secret, we bring you into the world of the code warrior monkey. I’m Father Robert Ballecer.

Shannon: And I’m Shannon Morse. For the next 30 minutes we’re going to get you all coded up, and everything you need to know to be a code warrior.

Fr. Robert: That’s right. Now we have some sad news. This will be the last episode of this module of python.

Shannon: But I was just getting into it.

Fr. Robert: I know, I know, this but is how it works, remember this is how we decided we wanted the show to work, when we created. We didn’t want to stay with one language too long because.

Shannon: Because we like to get everybody excited and then fail.

Fr. Robert: And fail. No, the real reason we do this is because we wanted people to realize that the important thing about programming are the concepts. It’s all about the concepts, the language is all secondary. You just learn the language, and as long as you know how to program, how that conversion of real world to machine code works, doesn’t matter what language you’re programming in, you’ll be a code warrior in any.

Shannon: You know, I’ve noticed, as we’ve grown, we started with C sharp and now we’re doing Python, that there’s so many similarities between all the different languages, but each one has a different context. They have different values at the end of each argument and whatnot. It’s so interesting.

Fr. Robert: And here’s the cool thing, now that we’re done with Python, we’re going to start a new language, we’re actually going to be moving over to Pearl…

Shannon: Yay!

Fr. Robert: And you’re going to get a rerun of those same concepts, so it’s like an instant, you know, memory dump.

Shannon: I’m so excited! Oh, that’s going to be so much fun. Get ready for Pearl is next. You heard it here first.

Fr. Robert: Now this is normally the time when we go into Snub’s compiled, but we had some breaking news.

Shannon: What kind of breaking news?

Fr. Robert: Well, evidently.

Shannon: Oh, boy. I’m scared.

Fr. Robert: We did not screw up the pronunciation of Tubble.

Shannon: I feel so much better.

Fr. Robert: Over the weekend, we got a lot of hate mail from people who were like “um, excuse me, its pronounced tu-ple

Shannon: Well you know a lot of people learn it differently from how I heard you say Tupple, so that’s how I derived it to be. But I’ve heard other people say tu-ple as well, so what’s right?

Fr. Robert: Actually, if you go to that page, I don’t know if you can zoom in at all, maybe enlarge the page. If you go to the pronunciation you’ll notice that in the IPA, the international pronunciation, it had both ways. You can say tu:pal, you can say ta:pal, it doesn’t matter, both are accepted. And this is one of the things that we tried to briefly touch on last week, which is, this is one of those words that either pronunciation is accepted. Like G:iff or G:if. So folks, all we’re saying is, if you know it one way, that’s fantastic, I love you, please keep calling it that, but open your mind.

Shannon: Open your mind.

Fr. Robert: Speaking of open minds, you’re going to go over tupples.

Shannon: I am. So this is really interesting for me, because I figured, hmm, I gotta send my vendor for my wedding guest names, tables numbers and whatever kind of food they want. And I have to sort these all into different ranges, I have to sort them by food so they know how many people are having filet minion or whatever, by table so they know whose sitting where. And then by alphabetical order so they can put out the place cards correctly on a table. It’s really confusing and it gives me a huge headache but having a tupple helps me sort that information out without having to do all the work on the back end. I just let the computer do it for me.

Fr. Robert: And again, we try to hammer this point last week, which is nice about these data sets, is you’re combining pieces of information that should go together. It’s one of those things where you didn’t actually have to, you could have different variables for each and every single one.

Shannon: Sure.

Fr. Robert: But there is something that is much sweeter. Something that is much better for again, the representation of the real world in computer language, when we take data sets.

Shannon: Absolutely. So if you guys want to switch over to my computer, I’ll go ahead and show you my example. This is my code, I didn’t include very many notes in here other than “sorts by food option” or I can change this over to, well, that was originally two. Number one is sorting by the table option. So I can change it to that. And then I just hit save. And when I open it, so it’s going to sort by table. So we first have Shannon, then Keith, then Mrs. Kauffman and Mr. Kauffman at two, Mr. Morse and Mrs. Morse at table three. And then I can go ahead and press enter to go ahead and continue from there. Now a few things that I would love to do with this code that I’ve already written is one, make it pretty so I can make each entry on to a different line, and then I could also export this into a text document so I can share it with my vendor. So there are so many other options that I could include in here. We’ve already learned all this stuff. So I could just compile all sorts of interesting information into this code.

Fr. Robert: Well that’s the cool thing about doing code like this. Where you recognize that it’s working, but getting it working is only the start. And we, if you’re going to become a code monkey, you’re going to start obsessing over those parts. You’re going to go “Yeah, okay, well the, the data is all right, but I want it to look pretty.”

Shannon: “I want to do this now.”

Fr. Robert: “I want this. I want it organized like that.” And those are the things that will make you learn.

Shannon: So we also got a couple of really, really cool viewer submissions as well, and I love these, so I just picked out my two favorite ones that we got in for the past week. The first one is from Lionel. So this one is called a deck shuffler. So if I make this a little bigger…

Fr. Robert: Isn’t he one of the thunder cats?

Shannon: He totally is. So he includes lots of notes which is wonderful. He commented out a whole bunch of notes in red. And then each of these basically brings in a whole deck. So he has an entire deck listed out in Python, and then he sorts this deck into a whole bunch of different outputs. And he uses tupples in here as well. So, if I run this code. Let me pull it up right here. There we go. So first off you bring in the deck and I should probably, there we go. So this is the unshuffled deck. Just has all the regular ones. Then you shuffle it. So it brings back everything it randomizes all the cards. And then you shuffle it again. And you can shuffle it one more time. After that it uses the objects. So it sorts by diamonds, hearts, I think these ones are supposed to be spades maybe? And clubs. And then you can shuffle it, shuffle it again. And then this is his last one, and if I scroll up a little bit, there we go. So this lists the deck objects. And then scroll back down and it shuffles it, shuffles it one more time, and closes out the… and we’re done.

Fr. Robert: Nice, simple program, you know, mix up some data and then you can sort it.

Shannon: Exactly. The last one I wanted to share, and this is from, let’s see who this is from.

Fr. Robert: By the way thank you Lionel, thank you Lionel, you are definitely Python, Python, Python pro.

Shannon: Ha-ha, perfect. So this one is from Jo. This basically takes the astronomy picture of the day and it downloads it to your same folder that you have the Python code in. and then it also gives you the description of the picture in your command line. So if I run this code, and I’ll show you what it looks like. So he imported a whole bunch of different libraries for this, including one that we’re going to be talking about today.

Fr. Robert: Oh, I love it, thank you for importing libraries.

Shannon: And then he enters in the picture, right here, and then includes the text. And that’s about it. So if I run this code right here. So it takes a few seconds for it to load. And then it brings up the picture.

Fr. Robert: Oh this one. I saw this on my Google+ page. That is a beautiful picture.

Shannon: Beautiful. Beautiful picture. And then if you close that out, or just minimize it. You’ll get also this little command line that opens up in Python, which is a description of the picture. What it is, where it’s from, when they took this picture, etc., etc. Very interesting, especially if you’re an astronomy nerd like I am, I love that kind of stuff. And now you’ll see the picture appears right here. Aha, so now you have a saved file of it. If they don’t have a picture of the day, if they do a video instead, it won’t download it, the video, obviously.

Fr. Robert: Right, yeah. I mean, I’m sure there’s a function you could use to do that but…

Shannon: Absolutely. But I really like those examples that you guys sent in. I thought that they were more advanced, but they were fun and they were useful.  I love astronomy, so that was a great one for me. I’m a nerd.

Fr. Robert: And again, it was a great example of using includes which we’ve already told people, are a great thing to pull into Python, because it allows you to use code that you didn’t have to write. And any time that you can do that it’s a good thing for a programmer.

Shannon: Absolutely. We have some more fun coming up but if you guys want to share your code, over at the Google+ community, we have Coding 101 on there. So you can go to gplus.to/twitcoding101.

Fr. Robert: Yeah, and actually, remember way, way back when we started this module I said, “I can almost guarantee you that we’re going to be at a thousand viewers at the end of the module.” We are at a thousand viewers, thank you so very much for joining the community, thanks for sharing the word, because that’s actually become an incredibly vibrant community.

Shannon: Absolutely, I love it.

Fr. Robert: On my phone I’m always doing the refresh, and there’s always something new in that community. Which is great, it means that you are really active and we thank you for that.

Shannon: I’m constantly downloading all of your code. And I love it whenever I can get it to work on mine.

Fr. Robert: Now when we come back we’re going to give you the low down on functions. Some of you have asked, “Why do you keep using functions in your programs when you haven’t really told us how to do it?” Well, we are not immune to criticism and if you want a good tutorial on functions, we’re going to break it down for you. But before that, Shannon.

Shannon: What?

Fr. Robert: You like the internets right?

Shannon: I love the internets.

Fr. Robert: The internets are kind of cool.

Shannon: The internets are awesome.

Fr. Robert: Yeah, I found cats.

Shannon: The internets is for …

Fr. Robert: Cats. Cats. Meow.

Shannon: Dogs.

Fr. Robert: Now, but here’s the thing, the internets a great place to share ideas right? The internets a great place to push our products, it’s a great place to get your presence known. But if you’re not a programmer, or let’s say you’re not a web programmer, or not a web designer, it can be kind of daunting. It’s not like the old days. My first web page was literally my name and a picture, an animated GIF of a guy doing construction.

Shannon: Oh, yeah.

Fr. Robert: And I thought it was the coolest thing ever. And it was all home baked, it was cool to me, but now looking back at it, because I actually found it on my hard drive the other day, I’m like, wow that was horrible, horrible.

Shannon: I saved all of mine before the old website got taken down, when it got destroyed.

Fr. Robert: But the problem with that is that if you are not a graphic designer it can be kind of daunting to design something that actually looks good.

Shannon: And nobody wants to go to a crappy website.

Fr. Robert: Yeah. Yeah. Which is why we’re very happy to have as a sponsor of Coding 101, Squarespace. They’re the one stop shop for designing for hosting for building your web presence. Now why would you choose Squarespace you may ask? Well, squarespace is an all in one platform that makes it easy to create your own professional website or online portfolio. Now I have used Squarespace in the past whenever I’m setting up websites for parishes, which are notorious for not having a whole lot of tech savvy people. With Squarespace they don’t have to be tech savvy. It does everything in the background and they get these beautiful looking sites with just a couple of clicks. Now what are some of the reasons why you’ll love Squarespace? Well first, they’re always improving their platform. They’re not one of these companies that are going to sell you a product and then sit back and take in the money while their designs and their structure are their code and servers get older and older and older. They’re always looking for new content and new ways for you to add pizzazz to your message. They offer new features, new designs and even better support. They, now, speaking of those designs, you can see Brian is going through some of the designs here, some of the content they have available. They have over 25 templates which are absolutely gorgeous for you to quickly build your own personal or business site. They also have a great mobile experience. This is important for anyone who realizes that more and more of this content is being consumed on mobile devices. It’s not just going to scale so you have a tiny little site on a tiny little screen, it will know that it’s on a mobile device, and as you can see on the screen here, it will scale it for you. It will change the content to be dynamic depending on someone looking at your site on a desktop, on a laptop or a mobile device. It’s also really easy to use. If you want help, Squarespace always has people who are willing and ready to answer your questions 24 hours a day, seven days a week via email and live chat. There’s also a completely redesigned customer website to help you with self-help articles and tutorials in case you want to push through. Now Squarespace also includes hosting, which means you’re not going to have to go to one vender to buy the buy the back end and another vender to register the domain and a third vender to give you the server space. No, it’s all in one deal with one price per month. That’s what I really like about Squarespace. Now it does start at just 8 dollars a month, which means it’s not going to break the bank and it’s something that you can experiment with. But that doesn’t mean that it’s just a beginner’s blog. This is something that can take you through from beginner to intermediate to advanced, depending on what you need and when you need it. Squarespace even has a developer platform which means that their code is beautiful and it means that if you want to dig into the site and customize it the way you want it, you’re not limited just to their 25 templates, you can tweak it according to your needs and according to your taste. Take as much time as you need before launching your site, and you pay nothing until it goes live. It’s all part of their commitment. To people who are developing creative sites. Now what developer platform I spoke of, also includes complete control so you can edit all the code that affects the display of your website, every line of HTML, CSS and JavaScript. Also Git and SFTP, so every template is a Git depository. That means that version control comes standard so you can always step back if there’s a change you don’t like. It also allows you to connect two templates via Git or SFTP, so you can share your work or get the work of others. Now here’s what we want you to do. We want you to try Squarespace. We want you to start off with a two week free trial with no credit card required and start building your website today. When you decide to sign up for Squarespace make sure to use the offer code “CODING” to get 10% off and show your support for Coding 101. We thank Squarespace for their support of Coding 101, a better web awaits, and it starts with your new Squarespace website. Boom.

Shannon: Bam.                                                                                                                  

Fr. Robert: Bam. Want to do some functions?

Shannon: Oh, I’m so ready.

Fr. Robert: Alright, alright. So, you’ve seen functions in some of the code examples. And some of the examples that we’ve actually brought on with Dale Chase. You know, it seems very similar to what we learned in C Sharp, but I think it’s a good thing for us to go back over them and explain what it is when we’re playing with functions. Now you know that when we define a function in any programming language, the idea is that we can write the code once, and then we can use it many times.

Shannon: Yeah. Absolutely.

Fr. Robert: So for example, if I have a menu or say, a function that brings in input from the user and then sanitizes it, or let’s say I have a function that does a particular calculation. Rather than typing that over and over and over again, why not just turn it into a function?

Shannon: Let the function do it for you.

Fr. Robert: Let the function do it for me, exactly. That’s what we’re talking about with functions, it’s an efficient use of code, an efficient use of your programing resources. Now when we are talking about functions in Python, all you need to know is def.

Shannon: Def, okay.

Fr. Robert: Like def. not like, you know… its d-e-f. That’s how you define it. So every function starts with the d-e-f keyword. Now then the variables are passed into the function via a prentices. I’m going to go ahead and show you what it looks like, if you go ahead and switch over to my screen Brian. This is what a basic function looks like. So this function up top…

Shannon: What in the world is happening there?

Fr. Robert: I actually, I stole this math from the Python.org support page, so I’m not going to try to say I did this. This is just a calculation that lets you figure out the Fibonacci series inside any number that you give it. 

Shannon: What?

Fr. Robert: Yeah. So what I’ve done here is I’ve used a def. keyword, kay, then I’ve created the name of my function, in this case it’s going to be “fib”.

Shannon: Okay.

Fr. Robert: And then this, in prentices, this is the parameter that I can pass into the function when I call it.

Shannon: Oh, okay.

Fr. Robert: So in other words, what this will do, is it will, when you call it, it will take whatever number you passed from it and then it will say “Okay, give me all the Fibonacci numbers between zero and that number.”

Shannon: Aaah, okay.

Fr. Robert: So that’s what that function does.

Shannon: So you’re defining the name of this sequence, called fib…

Fr. Robert: The function. The function is called fib.

Shannon: And then the input is the like the beginning number.

Fr. Robert: The value you pass to it. Right. The value that you pass into it. And then this is all the work that’s going to be done on that value.

Shannon: Okay, so that’s all happening on the back end.

Fr. Robert: Yeah, yeah. Now this function, so I’ve got a separate function here. This one’s called odd even. We actually did this one. This was, I think, episode 2 or 3 of this module. It’s going to take, it’s defining a function called odd even, and then it’s going to take the past variable called input, and it’s going to run it through these calculations. All these calculations will do is it will determine if the number is even or odd. Okay, very simple. We covered this, this was an earlier lesson, so I’m just bringing it back in. This one I kind of like. Remember how we told people, “please sanitize your input”.

Shannon: Sanitize your input. Yes, absolutely.

Fr. Robert: So all this does, when you call this function, and realize there’s no path. So you’re calling the function straight up.

Shannon: Oh, so you can do that?

Fr. Robert: Yeah, you can. Yep, so there’s no parameters on passing into the function. I’m using, this is simply a variation of the sanitization loop that Dale Chase gave us. In episode 4. It’s going to input a number using the raw input function here, from the user. And it’s going to put it inside of a loop until the function said, “Yes you passed me a valid result.”

Shannon: Oh.

Fr. Robert: Yes, so what it’s going to do is start off with a wild loop running, it’s going to input a number from the user, and then it’s going to do this “if/else” statement. If the number is a digit, then it’s going to set clean to zero which will make the loop stop. If it’s not clean, it’s going to say “that’s not a valid number” and then it continues.

Shannon: It’ll print out “that’s not a valid number.”

Fr. Robert: Right. This actually converts the string into a number. So you actually, now you have an integer value. And then this is important here, this returns the value to the code that called the function.

Shannon: Okay.

Fr. Robert: Mkay. So whatever value this code takes in, here it’s going to push it back out to the code.

Shannon: got it. A little confusing.

Fr. Robert: A little confusing but it’ll be made clear in just a bit. This is something that we always like to do. This is the main function. So this is the main part of the program right. So when I call this function, and again it has no parameter, you just run this function, it’s going to build a little bit of a menu, it’s going to call the sanitization function, right? And then it’s going to do an if/else statement and either push that value to the Fibonacci function, to the odd/even function, or its going to exit the menu. Or again, because we like to sanitize, it’s going to say “eh, that’s not a valid input.”

Shannon: So if they choose, if they type in 1, then it’ll do the first one, the Fibonacci, and then number two, then it’ll do the odd/even. And then after that, 3 to exit.

Fr. Robert: Right, right. 3 to exit. But if you type something else, it’s just going to say eh, nope. Now here’s the cool thing. My actual program consists of one line.

Shannon: Main.

Fr. Robert: Main. That’s all it is. So my, all of those things were defining functions. Functions can or cannot run. Right. If you never call a function, it doesn’t matter if you define it, it doesn’t actually run. So the only line here that actually does anything, is main. It’s calling the main function right.

Shannon: Oh, I get it. That’s cool.

Fr. Robert: And actually, that’s just really the way you want it, it makes it nice and simple.

Shannon: It makes it clean.

Fr. Robert: It makes it clean and it actually helps you to figure out what’s happening in your program, okay. So if I run this, this is what it’s going to look like. So “please enter a number”, I’m going to say seventeen. Kay, so “welcome to Padre’s useless number thingy!”

Shannon: That’s so cute.

Fr. Robert: It’s going to say “calculate the Fibonacci series, tell me if the number is odd or even, or exit”. So one, there are my Fibonacci series.

Shannon: Awesome.

Fr. Robert: Is the number even or odd? It’s odd. Now if I type something else. It’ll tell me it’s not a valid input.

Shannon: That’s cool.

Fr. Robert: I type three, it’ll kick me out. Now if I run it again, here we go, if I enter a number, if I entered an invalid number, so let’s give it a couple characters, because of the sanitization function, it’s just going to keep revolving in that function until it actually gets a valid input. And the way I coded it, the only valid input is a whole number. An integer. So if I put 3.14, it’s still going to tell me it’s not valid. Until it actually gets a number. There we go.

Shannon: That’s cool.

Fr. Robert: Now again, this is very simple, we like to make it cleaner, we like to make it a little easier to understand. We like to make the menu, what we’d probably do is clear the screen between selections.

Shannon: Yeah, I’d say so.

Fr. Robert: Of course I wrote this five minutes before we went on air, so I didn’t do that, but it’s a really good example of everything that could go into a program that you’re writing in Python. And this pretty much uses everything, except for tupples, and data sets. That we’ve taught people in this module of coding 101.

Shannon: So to review, you’re basically taking all these different functions and that one simple main line at the very bottom is calling these functions depending on what the user inputs.

Fr. Robert: Right, so Brian, if you go back to my screen. So this, before the compiler gets to that. All of this does nothing.

Shannon: Okay.

Fr. Robert: It does absolutely nothing.

Shannon: So it’s just going to be sitting in the Python code, waiting.

Fr. Robert: Just because you define a function doesn’t mean it’s done anything.

Shannon: Okay.

Fr. Robert: It just means that it’s there when you call it. So when I do this, when I call the main function, then Python says “oh, do I have a function called main? Yes I do, he defined a function called main”. Now let’s run down it. First it’s going to say, calculate= sanitize. Sanitize is another function I defined. So it’s going to go to sanitize and it’s going to run the code in sanitize. Sanitize is going to say, okay, we’re setting clean to zero, and as long as clean is zero, we’re going to run this loop. The loop is going to say, dirty input is equal to something that the user enters.

Shannon: And that’s why when you put in a bunch of gobbledygook it didn’t, it just said, that is not a valid number.

Fr. Robert: Right, because it got to the if/else statement. The if/else statement said, well if it is an actual digit, then set clean to one. And that while loop will stop running if the clean is set to anything other than zero. If it’s not a valid number, then the while loop will run again after printing “that is not a valid number.” So we’ll just keep asking. Once that while loop is done, it boots to the next line. And the next line is “clean input=into(dirtyinput)” and all that does is it takes that dirty input, now that I know that it’s a number, and it makes sure that it’s in integer format so that my farther calculations can understand it. And then it returns it to the code. That called the function. The code that called the function is main. Now I’m down here and I’m going into this other loop and this other loop deals with this menu. This menu will keep printing as long as I don’t exit. And here you see the call to the Fibonacci function, you see the call to the odd/even function, and that’s how it goes.

Shannon: And then exit. That’s awesome.

Fr. Robert: Yup, there you go folks. That’s, this is going to go into the Github, this is going to go into our show notes. And this is actually a really- what I would say, is if nothing else, if you get totally freaked out by what we’ve been doing with Pilot and all the advanced features, start with this menu, add your own functions, add your own features and make it look pretty.

Shannon: I wonder if my vendor contact would freak out if I just sent her this code and said “don’t worry, just run it on your computer, just go through the menu, you’ll figure it out.”

Fr. Robert: “Just do it, trust me, you’ll be fine.” Now when we come back, I think we need to welcome our code warrior back one more time. But before we do that, you know, I’m thinking, I’m  thinking that maybe I, now that I’ve got that Squarespace website, I might need to reach out to someplace that has really good creative imagery that’s available for me to use.

Shannon: I think that’s a good idea. You might need some good pictures, some good videos, to really show what you’re trying to tell your audience. I have a website for that.

Fr. Robert: What?

Shannon: Shutterstock.com.

Fr. Robert: Oh, yes, let’s do that.

Shannon: Have you heard of shutterstock.com?

Fr. Robert: I have, of course.

Shannon: This is the place to go for everything that you need. So this episode of Coding 101 is brought to you by shutterstock.com. At shutterstock.com you’ll find the perfect image, or you’re video Padre, for your next creative project.

Fr. Robert: Woot.

Shannon: Whether it’s your website, that you built on Squarespace, a publication, an advertisement, a video, or any other type of project, you can choose over 35 million high quality stock photos, illustrations, vectors, and video clips, so you have everything there. Right at the palm of your mouse. Shutterstock sources images from around the world. And they put them right there at your fingertips. Or at the click of your mouse. Many contributors to shutterstock are professional photographers and artists, which is way cool. So you’re going to get some excellent quality on there. Shutterstock reviews each and every image individually for content and quality before adding it to its library. And they add 20 thousand images every single day. So pretty much every time you visit, you’re going to find something new for sure. And they have flexible pricing, so say you just want one individual image, and you don’t need it that big, or you need 20 images and they all have to be you know, over 2000 pixels each. Well that’s no problem because they have either individual image packs…

Fr. Robert: Oh, they’re so cute.

Shannon: I know, so cute. Or a monthly subscription for the best deals so you can download twenty five images per day with a standard subscription. And you can download any size. Any image and pay only one price. Plus shutterstock gives you the images you need to bring your creative projects to the next level. And they make it easy. They have sophisticated search tools so you can search and drill down by subject, color, dog type, file type, gender, emotion, even more. Let’s say I want to find a picture, hey Brian, I want to find a really good picture of a bouquet for a wedding. B-O-U-Q-U-E-T I think.

Brian: Or flower.

Shannon: That works too. Okay there you go. So I want to find a good picture of a bouquet. Perfect. So I have plenty to choose right there. And it’s sophisticated so it knew exactly what I was looking for. They also have shareable light boxes. So you can save images to a light box gallery, and then access them anytime and share them with other team members. So you could always ask your friends, “Hey do you think this would be good for our collaborative project, for a website for we’re building. Is this the right color scheme?” An award winning iPad app is super, super easy to use and very intuitive so you can search on the go and use it to display images during presentations even. And they have a global marketplace. They have multilingual customer service, in more than a dozen international countries and full time customer support throughout the week. I absolutely love shutterstock and I think you will too. So you can try shutterstock today by signing up for a free account. No credit card needed. Just start an account and begin using shutterstock to help imagine what your next project could be like. And save favorite images to a light box to review later. Hey, you could share them with me even. Once you decide to purchase, use the offer code CODING514 and new accounts will receive 20% off any package. That’s shutterstock.com and for 20% off new accounts use the offer code CODING514. And I would like to thank shutterstock personally for their support for Coding 101. Thank you guys.

Fr. Robert: Hey, Brian, just wondering, how do you spell bouquet? It’s F-L-O-W-E-R-S?

Brian: Yeah, it’s pronounced bouquet, but it’s spelled like flowers, it’s really weird.

Fr. Robert: Got it. Well, you know, the pro tip. Thank you, thank you.

Shannon: He’s so smart.

Fr. Robert: Well now that we’ve got our content out of the way, I’m thinking, we welcome back to the show, one last time. The man who brought Python to the masses, who opened our hearts to the love of piglet, ladies and gentlemen, from Discovery Digital Networks, its Dale Chase. Dale, thank you for coming back.

Dale: You don’t have to cry for me Shannon Morse.

Shannon: I love you Dale. He’s just like “Oh, God”.

Fr. Robert: Dale Chase, it’s so good to see you again, how are you?

Dale: What’s happening? Where’s my 21 gun salute.

Fr. Robert: I’m sure, actually we’ll get, let Brian get on that. Now sir, now last week you blew some wigs. People were freaking out, saying what is going on. Did you want to continue with the mind blowage this week?

Dale: Ah, no, I think we’ll take sort of a bit of a step back this week.

Fr. Robert: Thank you, because you were, people were really hurting.

Dale: I was hurting a little bit. I ended up trying to actually wanted to take it a step farther but I ended up having some issues with piglet on my machine. So it was probably me, I’m not sure what I was doing, but yeah. I couldn’t really go much farther with it but I decided to go with tikentur, or is that even the pronunciation.

Fr. Robert: You know, we’re not even going to argue pronunciation, we’ve learned our lessons.

Shannon: You know, I was checking this out last night too and I just figured it was tinker but who knows?

Fr. Robert: But pi-glet, I kept calling it piglet. It makes sense. I’m going to call it piglet. Let’s go, we’re going to call it the T thing. Tell us all about this t thing.

Dale: Well I haven’t used it too much but it’s something that comes with most instillations of Python actually. It’s a graphic user interface for Python. So you can actually do a little windows and labels and buttons and text and lines and all kinds of cool things to kind of give your Python programs an actual application feel.

Shannon: Yes.

Fr. Robert: Oh, by the way, I would like to point out the fact that the Q in the chat room gave you a 21 gun salute inside of a c sharp 4 loop.

Shannon: That’s awesome.

Dale: That’s awesome.

Fr. Robert: Well done, well done sir. Alright now, so the advantage to this of course, is that we don’t have to go out and get it. We don’t have to get a package elsewhere, this is built in to the python instillation. There it is, thank you. “for(into i=0; i<=21;++){//salute}”.

Dale: Awesome, nice.

Fr. Robert: Alright, now show us. Show us how this works.

Dale: Yeah, I just did sort of a basic window with some squares and lines going on. Basically here’s what I’ve got and I’ll show you what I’m doing here.

Shannon: Slow your roll.

Dale: So this is just a little window that’s plotting 5 squares, sort of randomly. And it’s bringing some text to the screen. And then if I click this button here “draw a line”.  It draws a line.

Shannon: Oh.

Fr. Robert: Oh.

Dale: So.

Shannon: Yay geometry.

Dale: And all that’s accomplished in just a few relatively simple few lines. All I’m doing is importing from tkinter, so from tkinter importing everything.  And to do my sort of random square, pseudo random square placement, I’m porting random. The random module. And so since you guys are doing functions I just wanted to put my “draw a line” as a function. So but ill skip that for now, I’ll come back to that because that’s kind of declared out here. So…

Fr. Robert: This is awesome, this is all coordinate system geometry. This is super easy.

Dale: Yeah, yeah absolutely. I mean, you can get more advanced with it, but this is just the simple, you know, kind of get you going with the simple stuff. So I’m instantiating the class here, the tkinter class, we’re calling it “tk”. And then I am creating the window, the canvas, using the, my instiation of tk and then …

Fr. Robert: Right, you give it a size.

Dale: Yeah, 200 by 200 pixels. And then this pack function essentially displays it and then I’m creating the little text.

Fr. Robert: That goes inside, right.

Dale: Yeah, so this text right here…

Fr. Robert: Yeah, cool.

Dale: So that’s created by calling canvas.create_text. So I’m putting this text on that window I’ve created.

Shannon: Oh.

Dale: Setting the x and y value. The x and y coordinates for where I want the text to be placed.

Shannon: Is that the pixels?

Dale: Uh, yes.

Fr. Robert: Yeah, so that’s just x y coordinates right. So you’ve got the x y coordinates of the text, where it’s going to start, then you have the text itself. So you’re passing it what, 3, throughout 4 different parameters. The starting spot, the text itself, the font that it’s going to be in and the fill of the text box.

Shannon: Ah, the color. Okay.

Dale: No, actually this is the fill of the color, of actually the text itself.

Fr. Robert: Oh, okay. Got it. That makes sense.

Dale: And so as you see, I’ve just actually changed that text to an actual message that we can both see next time I run it.

Fr. Robert: It has a function to create a button. I love that, that’s aw, okay. It’s like the visual languages now.

Dale: Totally. So yeah, so I’ve got this variable, btn, which I’m assigning a button to. And again, just like creating the window, I’m calling it a button using the class I’ve instantiated and labeling the button “draw a line”. So here’s where the function I declared earlier comes in. this is the sort of a callback. But it’s so, here’s the command, and then I want the command to be when I push the button, to call my function draw line. So when I push the button it’s going to run this function. Draw line.

Shannon: Oh. Oh I see what you’re doing.

Dale: Which puts canvas.create_line at 5, at x5, y5. And 100, wait, it’s a line, so why do I need two values for 100. Yeah, so it draws the line there.

Shannon: And you’re giving it coordinates. So it’s not going to be a random line, it’s going to start and end where it tells you to. Or where you tell it to.

Dale: Right. Right. And oh yeah, of course, I needed to. I’m sorry, so these are my x and y coordinates for the start of the line and the end of the line. Forgive me I’m…

Fr. Robert: Yeah, you know what, it’s a Thursday and I think we’re kind of, brainfart.

Dale: So then down here I’ve got a little bit of a loop, kind of pulling it to something else we’ve already covered. So my loop is a range of 0 to 5. And so x is going to be taking that value, so I’m, wait, why did I do that? Oh hold on a second. So I actually, so alright. So I should actually change this. This is why this is, let me make this J.

Fr. Robert: While you change that, we’re getting a comment in the chat room from Harlequin who is saying “oh, coming from Csharp, Python is quite unattractive to look at.” It’s very, very different. Csharp was a visual language. So of course it’s kind of pretty. You know, it’s a nice pretty window and it tells you exactly what values you can choose for individual functions. Well one of the charms of Python has always been the fact that we can be in notepad, we can be in any text editor and we can pound out code and run it through an interpreter. It’s a little faster and it’s a little lower barrier to entry than Csharp. You know, again, different language for different purposes.

Dale: Thank you, that gave me some time to get this line in order. So basically I want this to loop through 5 times and just draw 5 rectangles. And then I’m creating a random number between 0 and 175, and assigning that to J. and that’s just, I’m just using that as my x and y values.

Fr. Robert: Right.

Dale: Just sort of put it somewhere.

Fr. Robert: So it’s going to start at a random spot and it’s going to end at 25 25.

Dale: Uh, no. the 25 25 are the sides of the rectangle.

Fr. Robert: Oh, I’m sorry, yeah. That’s right.

Dale: Yeah. So this is the width and height of the rectangle.

Shannon: And outline being in purple, that means that the rectangle is going to be outlined in purple.

Fr. Robert: I hope so.

Dale: That’s correct. And I can actually use the fill here too.

Fr. Robert: Just like you did with the text, you can fill with a particular color.

Dale: Exactly. Yes ill fill that with…

Fr. Robert: Can you say red? Red.

Dale: Red? Alright, we’ll go red.

Fr. Robert: Run it. Run this bad boy.

Dale: Let me clean that up. And so yeah, it’s uh, I’m using raw input, slow your roll, to keep it from disappearing. The window from disappearing. And so there you have it. And Shannon is off the screen.

Shannon: It worked.

Fr. Robert: Well Shannon is off the screen. She’s off the hook.

Dale: The new off the hook, off the screen. Aright. And then there’s my line again.

Shannon: It worked!

Dale: Yeah.

Fr. Robert: Now, okay. I know for a fact that this is so much more accessible than piglet was for our crew. I had trouble with piglet but if this is integrated into Python, if this is something that I can just include, yeah, suddenly, why not. I think this is absolutely, I mean, the little menu program that I just did, I could have put all of that inside of a box, I could have given it some nice colors, I could have had a nice font. Rather than just standard asky art.

Shannon: Oh, yeah, you could have. Hmm, maybe I should send that to my vendor.

Fr. Robert: There we go.

Shannon: She’s going to hate me so much.

Fr. Robert: Dale Chase, you are awesome, we want to thank you so very much for being on our code warrior. We’ve really sort of, with you, we’ve defined what the code warrior is. Because the code warrior with Lu was great, he’s an incredible teacher. But what we really wanted, is we wanted someone who could sort of step off the page of what we were doing and just push forward the young code monkeys in their nasian state. And that’s what you’re doing sir.

Dale: I’m glad I can be a part of it. It’s been a lot of fun and a learning experience for me as well.

Fr. Robert: Yeah. And we’re going to have you on the twit network as much as we possibly can because you’re an incredible talent. In fact, Brian if you could, could you give us some tunes? I think we need a little something to listen to as we, oh wait.

Shannon: Oh, I know this song. They play this one at DefCon.

Fr. Robert: Now Dale. Discovery Digital Networks. You’re also your own man, your own artist, can you tell us what this is that we’re listening to right now?

Dale: This is a song called Word Press off of my Limit Break album, featuring some good friends of mine, Dual Core, M80 and C64. Yeah. I love rocking with those guys.

Fr. Robert: Yeah. What we actually issue this challenge to everyone out there, if you are getting into Python, download some of Dales music and listen to it. Because it’s all an inside joke.

Shannon: Listen to it while you code.

Fr. Robert: It’s all an inside joke. If you code you’re going to start going “oh, did he really just say, oh my God, I use that line all the time”. That’s what his art is all about, it’s about merging his passion for music with his intelligent coding.

Dale: Yes. That’s right.

Fr. Robert: Okay, now we know that they need to go to your download page, but where else can they find you?

Dale: dalechase.com. @daleochase on twitter and yes, dchase.bandcamp.com.

Fr. Robert: Ladies and gentlemen, Dale Chase. Discovery Digital Networks. We thank our second code warrior.

Dale: So long guys.

Shannon: We love you. Salute. Bye Dale.

Fr. Robert: Dale don’t go. Dammit Brian.

Shannon: That’s okay. We’ll bring him back.

Fr. Robert: Now, folks. We know this is a lot of information, we’re always going to include really, really exhaustive notes in our show page. Shannon where can they find our show page?

Shannon: Twit.tv/code and that’s where you can find the link to our Github as well.

Fr. Robert: Exactly. And in our Github are actually all the coding examples that we gave you. So the code that Dale just showed us so that you can make nice little boxes in your Python, it’s going to be in there. The code that I created to show off the defining of functions, that’s going to be in there.

Shannon: My super simple tupple is going to be in there.

Fr. Robert: Her super simple tupple is going to be in there. So if you have any questions about what we did on the show, you don’t have to keep pausing, although you can. You can just download our code and try it for yourself. Now also, you’re going to find us on iTunes. And we want to thank everyone out there who keeps subscribing to us, making us one of the most downloaded podcasts on iTunes. That’s absolutely fantastic. And please, please continue to share the news about Coding 101, it’s not just for people who want to program, it’s for people who want to understand what programming is all about.

Shannon: Absolutely. And we’re also on YouTube, over at youtube.com/twitcoding101. And we definitely check out all the comments over there and I’ve been trying to keep up with everybody and check what you guys want to see so. Thank you so much to everyone who has been watching the show over on YouTube.

Fr. Robert: You’re very good about that. Also you heard Shannon mention earlier that we have a G+ community. You can find us at gplus.co/twitcoding101.

Shannon: Or plus.google.com/twitcoding101.

Fr. Robert: Or plus.google.com. Go there because, again, it is a vibrant community. It’s over a thousand people, its expert programmers, its new programmers, its people who are just curious about programming, and tell your friends, tell them to get in there. Because the more people we have in that community, the more useful it becomes.

Shannon: It really is, yeah. It’s so great. Like, even if I have a question, which I do on several occasions. I’ll just go in there and be like “why isn’t this working?” and they’ll be like “Oh well just fix this one line.” Oh imagine that.

Fr. Robert: Of course if you’re not into the G+ groove you can also find us on twitter. Where are you snubs?

Shannon: I am @snubs.

Fr. Robert: Yeah, and I am @padresj. Now next week we are not doing Python, in fact for the next two weeks we are going to be doing our wild card episodes. Remember those between the Csharp and the Python modules where we got to talk to actual programmer’s right.

Shannon: Liam Kennedy.

Fr. Robert: Liam Kennedy, and we talked to Amanda Schwartz. It was a fantastic time to actually sit down with people who do this for a living and find out what makes them tick. So we’ve got two brand new guests coming for you before we head into Pearl, but until that time, I’m father Robert Ballecer.

Shannon: I’m Shannon Morse, end of line.