From the course: Introduction to Career Skills in Software Development

Solution: What's the output? - Python Tutorial

From the course: Introduction to Career Skills in Software Development

Solution: What's the output?

(upbeat intro music) - Are you ready? Let's work our way through the code line by line to figure out the output. Starting on line number one, we use the print function to print out a message, "Challenge 1" on a line by itself. So that's the first line of our output. Then line number two is a blank line. We know that Python will just ignore it, so there's no output from it. Onto line number three, it starts with a hash mark. This means it's a comment and Python will ignore it. No output here. So far, so good? Now onto line number four. We have our first variable. When I encounter a variable, I create a box for it and write down its current value in pencil. If it changes later, I will always have the current value. For now, message equals "This is my message" and nothing else happens on this line. We can go onto the next one. Here, we have another variable, note. Again, we can create a new box to represent this variable and its value. Onto line number six, our familiar print function. It prints out the contents of the message variable. If we look at the contents of our box then we have our next line of output, "This is my message." Line number seven is a blank line. Nothing to see there. Then we have another comment on line number eight, no output there. Hopefully you're starting to get the hang of how Python ignores white space and comments. On line number nine, we introduce a new variable named result. Let's create our box for it and write down its value. Did you remember that an asterisk represents a multiplication operation in Python? This means two times three, which is six. Therefore, the result variable equals six, and on line number 10 we're going to print it out. We're almost done. Just a few more lines of code to parse. On line number 11 another empty line. And finally, line number 12. We print out, "Challenge complete!" Were you able to figure out the output on your own? If so, that's awesome. If not, that's okay too. It takes lots of time and practice for most people to really understand how these things work. Just keep going.

Contents