Part One - Your First Program

10 1 0
                                        

So the first thing you want to do is install Python. I will not cover this in this book but I added some hyperlinks to the sites that teach you how to do that. 

Windows: https://docs.python-guide.org/starting/install/win/

Mac: https://docs.python-guide.org/starting/install/osx/

Linux: https://tecadmin.net/install-python-2-7-on-ubuntu-and-linuxmint/

Chromebook: First install Linux beta from the settings. After that, open the terminal and type suo apt install python2

For some other weirder versions they use yum but most use apt install.

Now open a text editor and save the file as Project_One.py


Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.


Now, you should be able to use python. And yes, I am using a Chromebook. To use the program you actually do it in the terminal. If you use the Debian terminal type: python2 Project_One.py


Once you do that you should get no errors. But it will also do nothing. That is because we haven't typed anything! If you want to print something to the terminal you use the command print. This will just return something to the terminal. If you type...

print "Hello my name is"

... Then it will return Hello my name is. Now type python2 Project_One.py into the terminal. If you have no errors it should just return Hello my name is. Some common errors are forgetting the commas. Also if you capitalize Print like that it will return an error. That is really boring. Let's spice it up with variables. Variables just store data. They store different types of variables too!

int, float, string, bool just to name a few. If you want to learn all of them there are huge lists out there. Here are how variables work.

variable_Name = value

Here are some examples:

int - Just_Some_Numbers = 56

float - Random_Numbers = 67.359

string - Random_Words = "Hello Readers"

bool - Some_Cool_Name = True 


int will just hold whole numbers. It can also hold negative numbers as well. 

a float can hold numbers with decimals.

a string will hold a value of characters. It can hold like sentences but it can also hold numbers it just can't be used in math 

bool can only hold True or False. This can come in handy when making a program! 

Now back to the code! If you use variables you can open up to many opportunities. In your code above the "print statement" put:

Name = "Put your name here"

print "Hello my name is"

If you want to add the variable Name in your print statement you can "Concrete" it. This is combining a print statement with a variable attached to it. In your code put in the print statement:

print "Hello my name is " + Name

If you add this it will print out Hello my name is, but it will also print out whatever you put in the Name variable. Now, this is kinda cool but let's make it better. Instead of you putting the value of the variable you should ask the user. In your code put:

Name = raw_input("Enter your name: ")

print



You've reached the end of published parts.

⏰ Last updated: Feb 26, 2020 ⏰

Add this story to your Library to get notified about new parts!

Learning Python: Level One - The BasicsWhere stories live. Discover now