WSQ02 – “Hello World”

This one’s pretty simple, just print “Hello World”. It’s a very common thing to do when you’re learning a new programming language, and in regards to this I’ve found a like for codecademy, I think it’s great for learning languages as it safely takes you step by step in a very interactive way. I used it to learn python and finished the course in less than a 24 hours, and although I can’t say I master the language, I do know how to do what I need.

But back to coding issue, python is very very simple. For your program to print “hello world” you just literally need to type:

———————————————————————-

Screen Shot 2016-02-06 at 4.56.58 PM

———————————————————————-

Yes, as easy as that. This should work for both, python 2 and 3. I do rather work with the former, as most of the forums and help you may be looking for are most likely found in that format, but the differences are minimal. The big difference about both versions in regards to this hello world code would be that python 2 accepts print with or without parentheses, while print will only work in python 3 if it has them. input and raw_input is also another big difference, and speaking about it I might as well start using these:

———————————————————————-

Python 2:

Screen Shot 2016-02-06 at 5.02.17 PM

Python 3:

Screen Shot 2016-02-06 at 5.04.27 PM

———————————————————————-

Now, if you’re new to python, I’d like to encourage you to try to figure out what this means before reading the explanation. 

Here, whatever you write in between the parentheses will show on the terminal/shell. raw_input/input is for the user to write and input something into the program, the code right here will print whatever the user inputs. But it only does it once… so what if the user wants to print more than just one message? Worry

Screen Shot 2016-02-06 at 5.19.03 PM
Screen Shot 2016-02-06 at 5.19.03 PM

loops and conditionals do exist in python:

———————————————————————-

Python 2:

Screen Shot 2016-02-06 at 5.19.03 PM

Python 3:

Screen Shot 2016-02-06 at 5.19.03 PM

———————————————————————-

There it is, we made the variable cont equal to the string “Y” so that the while loop stops when cont isn’t equal to “Y” anymore, unless the user wants it to. So what if he types anything else rather than “Y”? What if he types it lowercased? The program would stop running, and yes, we’d have to make some modifications to our beloved code. But that’s a story for another day, and another practice.

This post is for my #WSQ01 on the programming fundamentals course. 

CC BY-SA 4.0 WSQ02 – “Hello World” by esenombredeusua is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.