Skip to content

Python Basics @ Coding:

Python is a popular (easy-ish) coding language that you can use for a variety of purpose. It was created by Guido van Rossum, and released in 1991.

What can Python do?

Well you can use python for:

  1. Web Development. (Server Side)
  2. Software Development.
  3. System Scripting.

Python can create web applications, workflows, compute and calculate mathmatic questions, connect and do database queries and for rapid prototyping and testing.

Getting Started:

EVERYTHING you will learn can be done in a web IDE. We reccomend using online-python.com! Click Here to Visit

Everytime we say "Now You Try". Please use online-python.com to demonstrate your skills.

1. Print:

Lets get started with print().

  • Print simple outputs the thing you typed it to output. For example:
print("Hello World")

The terminal should return: Hello World.

  • Make sure you always have the brackets.

2. Random and IF Statements:

Let's dip our toes in if and using the random library.

  • To use a library in python you must import it first. Example: import random
  • To get function, variable or etc from a library do: from random import randint (On the line below)

Now lets use the random library to generate a random number between 1 and 20.

import random 
from random import randint 

number =  random.randint(1,20)
print(number) # When in the brackets. You do not need to put speech marks in for variables! 

Now you try!

Adding a IF Statement:

To add a if statment to the code. We must decide what should happen incase of...

  • So lets say if the number is 10 it prints "10 + 10 = 20"
import random 
from random import randint 

number = random.randint(1,20)

if number == 20:
    print("10+ 10 = 20")

3. Multiple IF Statments:

When having multiple if statements. You can replace if with elif:

import random 
from random import randint 

number = random.randomint(1,20)

if number == 1:
    print("1")
elif number == 2:
    print("2")