Skip to content
Guide to Python: The Complete Guide [In Progress]
Profile icon

Last updated 1/10/19

Welcome to Guide to Python

Simple lessons for beginners by beginners.

Lesson 1

The Basics


print() and variables and math


So, print is a function. A function is a command that does something. I'll cover more of them later, but print is the most basic.
WHAT IT DOES: prints something (in the IDE [the IDE is the module that your code runs in])
how to print a number: just type it in the parenthesis
how to print a variable: just type the variables name
how to print a string: SUPER COMPLICATED - put quotation marks/apostrophes around the string [e.x. print ("hello world")]
how to print a mix of the above: SUPER COMPLICATED - put a plus in the middle

print(str(15) + " bananas")

15 bananas
ez (except for maybe string, what that function does is converts it to a string so that it can be printed, only strings can be printed)
ok next thing


I better cover this fast so you can start putting them in print functions.
A variable is data thing that stores a value. For example, if you set a variable called "favorite_fruit" to... idk "banana" then you can do print(favorite_fruit) and the output is banana. Or you can store a number, a fraction, a decimal, all that good stuff. And because python is awesome, unlike other languages, you don have to define whether a variable is a string (oh if you don't already know a string is text), a number or a float (a decimal)
You set variables with

variable_name = value

i know so hard

and you can change variables too, there not just stuck like they are forever

variable_name = value variable_name = 'chicken'

now the variable is chicken

you can set variables to numbers by not using the quotation marks
and you can do math with variables, and even set the variable to a user input.
lemme explain input in a couple sentences
its like print but the user has to type something and press enter before it continues. using variables you can store the user's response, or you could just ask a yes or no question with

#oh quick facts = sets something and == checks something if input('Are you 13 years old') == yes: print('Yay! I guessed your age!')

So yeah back to variable math

while True: quickmath = input('Type a number') #combining this with the first script, lets use try except to make sure they enter a number try: quickmath = int(quickmath) break except ValueError: print('no a number. try again') print(str(quickmath + 10) + 'is your number plus 10')

comment if you need me to do more about this. time to get into math


oh this is real easy. So. Python can do maths. As you've seen in the previous examples. It can do the basic four, +, x, -, ÷. And modulus and percents and some other basic things. If you've run out of math things do import math for more math stuff. ok bye

If, Else, Else If,

Another easy one:
For If, you do if, then what your testing, then a colon:

if variable == 5: print('variable is 5')

Else is pretty much just if not what you said in the above if statement

if variable == 5: print('variable is 5') else: print('variable is not 5)

Easy, right? And Else if is another if statement if the first is not right.

if variable == 5: print('variable is 5') #NOTE YOU DON'T USE 'ELSE IF' YOU USE 'ELIF' elif variable == 6: print('variable is 6') #You can add as many else if's as you want elif variable == 7: print('variable is 7) else: print('variable is not 5, 6 or 7')

and now...

Part two


Welcome to Guide to Python

Simple lessons for beginners by beginners.

Lesson 2

The "Try - Except" thing

The basics:

It 's similar to the If - Then statement in the way that they both test for something.

What it does:

The Try part will attempt to complete the actions below, for example-

variable = input("Type a number") try: variable = int(variable) --------------

This will ask for a number and then attempt to make the variable into an integer. If this was outside the try circuit, then you would get "ValueError" if the user did not enter a number because a string cannot be converted into a number (with int).
However, it's inside the try circuit... So now, with the Except thing, we can test for any errors and do something before we are outputted the error. Lemme show you what I mean:

variable = input("Type a number") try: variable = int(variable) #If the above command works, then break will get you out of the loop break #The except looks for the given error and will do the below actions instead of giving the user the error except ValueError: variable = input("I said type a NUMBER! Try again!")

Put the try except thing in a while true block... and it'll keep asking until you give it a number.

That's all for this lesson as of now, look for updates!

Alright that's all. time for lesson 3 i guess?

Welcome to another section


basically if ur too lazy to type a bunch of commands make a function


Welcome to Guide to Python

Simple lessons for beginners by beginners.

Lesson 3

Functions: Define one and Use One

How to use a function:

Well tbh it's pretty easy just type the function name and the parenthesis after it. If it needs an input (like print or str...) seperate the input's by commas.
So that's all the time that I'm gonna spend on that. If you need more I'll add more.

Onto actually creating functions.

How to create a function:

Use "def [function name](inputname, inputname, inputname...):"
Say how about a function that takes a number and adds 10.
so, the function needs an input (the number) and an output (the number + 10)

def add10(inputed_number): return inputed_number + 10 while True: number = input('type a number') try: number = int(number) break except ValueError: pass print (add10(number))

the first line is the aforementioned define line
the second returns/outputs the number (the value is given to the temporary variable 'inputed_number') plus ten.
now the actual script starts, after we have defined our functions
the third through eighth is our try except loop
the ninth is also part of the loop, but i wanted to explain it. it pretty much does nothing, it passes. I don't need it to do anything because the loop will make it ask for a number again. normally i would do (print("that's not a number!")) but i didn't want to, so i just skip it
the final tenth line runs our input through our function and prints it

You can make a function do anything, hopefully this example show's their power.


If you ever need help with any python, you have four options:

  1. contact me
  2. check the tutorials here on
  3. (site for questions about literally everything coding)
  4. google

made for challenge

You are viewing a single comment. View All
Profile icon

how do i use the loop example