I just finished installing Python! Yay! I needed to first make sure that I did not have it installed on my computer. So I opened up my Windows Command Prompt (cmd for short). All I needed to do was type in the cmd the word "python" to see if I had it installed or not. And sure enough, I did NOT have it installed.
So off I went to the python.org site to download my python. I downloaded the latest version for Windows which is 3.5.0.
During installation I made sure to choose an option that says "Add python.exe to Path" and then voila! It's installed!
But first I wanted to make sure that it was indeed installed on my computer. So I brought up my cmd and I typed the word "python" just to make sure. And what happened? This is a screenshot of what happened.
It worked! It even typed what version of Python I just installed which was 3.5.0. I decided to take it one step further just to make super sure. Do you see the symbols ">>>" on the cmd screen? I learned this means that you can now start barking out commands in the Python language. So let's see what happens if I type in 8 * 9 and then press enter. Wow...it worked! It gave me the answer!
What happens if I type a simple string? I am going to type "Hello Fearless Alien Leader Jo" to see what happens.
It gives me back the same string! Awesome! Now to exit out of the Python program in the cmd I just type without quotation marks either "exit()" or "quit()" or press down on the ctrl + z keys and it will get out of the Python program and go back to my Windows command prompt.
I also learned how to save a Python program and then call it from the cmd. I love using my Sublime Text 3 editor and I installed a package called Anaconda which is an awesome Python plugin with many cool features thrown in.
All I did was write two simple lines in my Sublime Text 3 editor and saved this file with a "py" extension to my desktop. I named my file "pythonfun.py."
I then opened up my cmd and typed in without quotes "cd desktop" and then typed without quotes "pythonfun.py" and this screen came up:
Hmmm...there seems to be a syntax error! It seems that not only did my math equation not print out the answer but it also says that I am missing a parentheses when I called the word print in my text editor. WTH!
So I decided to do some research and discovered that in Python 3 parentheses on print is mandatory but in Python 2 it is not. In Python 2 there is no need to wrap any text that you want to print out in parentheses unless you want to. But in Python 3 the word "print" is treated as a function and therefore you need to put the items you want to print inside the parentheses or you will get a syntax error, just like I did!
So I went back to my text editor and added the correct changes to it so that it looked like this:
And when I saved it and called it through my cmd this was the glorious result:
It worked! So that was the problem! I also noticed that I should implement the same thing in my cmd Python prompt. Cause if I were to type into the Python command prompt the word "hello" without quotes this is what would happen:
It said "NameError: name 'hello' is not defined." That's fine since I don't want it to be defined. I just want my cmd to print out the word "hello" without quotes. So I typed in with quotes "hello" and then what happens? The cmd is still replying to me with a hello that has a single quote in it! So what happens if I play with the parentheses and type ("hello")? It still prints the hello word with single quotes! C'mon Jo...think...Okay...let's experiment some more.
What happens if I were to use the word print "hello" instead? I got another SyntaxError where it says that when calling the print word that I must enclose what I want printed in parentheses. So I typed in print ("hello") and guess what? It finally worked! And it gave me what I wanted which was the word hello without any quotes! And I decided to experiment with what would happen if I typed in 9 * 2 without putting the print word in it and that worked too. It gave me the answer of 18 right on the cmd screen. I took my experimentation to a whole new level and typed print 9 *2. And this is what happened:
I got another SyntaxError saying that I needed to call a parentheses when I used the word print. And if I do what it's telling me to do and I type in print (9 * 2) it will give me the same exact answer of 18. So it seems that with numbers I can just type in the Python command prompt 9 * 2 or print (9 * 2) and it will give me the same exact answer. Well that's good to know! I just learned something new today. And now that I accomplished my mission it's time for the Woohoo Dance!