-Home page -Compiler

Introduction

Welcome! My name is FunTSM and i have made this website to teach you how to code python. For some context i have been coding and making games since i was in second grade, i also like to work with circuitry and 3D printing. I started learing python in 2023 when my good friend MaCool agreed to start teaching me. Now i have built several programs in python, and learned quite a few more things.

Usefull tools

Before we begin i would like to give you some tools to help you along your journey, one really good learning tool is W3 schools. When they teach you about python they also let you run your code in the site, and they have tutorials for a wide variety of python things. One other usefull tool for making and saving code is Replit if you sign up for it you will be able to save your programs and work on them over time. The last thing i will talk about is a compiler, you do need some compiler to run your code, but to save you the time of finding a good one i have one right on my site! just click the link labeled "compiler" in the top left and start making your code right there (compiler made by trinket).

The basics

Hello world:

When you are learning a new programming language the first thing you do is print "Hello, World!" to the console, to do this in python you

print("Hello, World!")

Ta Da! now you can print words to the console, Congrats!

Variables:

The next thing we will learn about is Variables, Variables are used to store data think of them like a box with a label where you put stuff for later. There are many types of variables including (but not limited to):

#strings(stores text)
variable = "Hello, World!"
print(variable) #will print "Hello, World!"

#Integers(stores whole numbers)
variable = 8
print(variable) #will print 8

#Floats(stores numbers with decimals)
variable = 0.3
print(variable) #will print 0.3

#Boolens(Stores a True or False value)
variable = False
print(variable) #will print False

#Lists(stores a collection of items that dont have to be the same type of variable)
variable = ["item 0", 2, 5.4 , True]
print(variable[0]) # will print "item 0"
print(variable[1]) # wil print 2
print(variable[2]) # will print 5.4
print(variable[3]) # will print True

#you can also combine variables with text in a print statement
variable = "world" print("hello "+ variable)

If Statements

The next thing we will talk about is if statements, if statements can ask a question about a value and will run a section of code if they return true.

Variable = True

if Variable == True: #since our variable does equal True it will print
  print("True")
        
if Variable == False: #since our variable does not equal true it will not print
  print("False")

if statements can also be used to check what strings and numbers equal

variable = "Hello world"
varnum = 8

if variable == "testing":
  print("variable does equal testing")

if variable == "Hello world":
  print("variable does equal Hello world")
  
if varnum == 8:
  print("it does equal 8")

if varnum == 9:
  print("it does equal 9")

In this example if we make our variable equal "testing" it will say it does. If our variable equals "Hello world" it will print that it does. with our numbers if our varnum variable does equal 8 it will say so, and if it equals 9 it will say so.

Comparators in if statements

When you make an if statement you dont have to use the ==, you can also use a whole varitety of other ones. most are just used to compare numbers but two of them are used in all kinds of scenarios, the types are:

Advanced If statements

If statements dont have to just ask one question or have one output, with the use of elseif and else addons they can do much more, for example:

variable = 8

if variable = 9:
  print("variable equals 9")
else:
  print("variable does not equal 9")

In this example if we set our variable to 9 it will print "variable equals 9", but if we set it to anything else it will print "variable does not equal 9"

Another thing i mentioned earlier was the elseif, the elseif is another if statement that is only asked if the first one fails, so if you have one if statement and that one equals false, then it can ask another if statement, and possibly even another, and another, ect. There is many cases where this can be very usefull, one thing you can do with it is speed up your code as your program will be asking less questions

User Imput

This wont be a very long section because there isnt much to talk about here. user imput will allow you to ask a user a question then save their response into a variable. to do this you use the "input()" function like so:

name = input("whats your name?:")
print("why hello there "+ name")

This should greet the user with whatever name they put in for themselves

Lists

Lists are such an advanced type of variable they can(and they will) have an entire section just about them. Some of the many things i will talk about here is all the different funcitons you can do with a list. Or that you can put lists inside lists!

One thing that is pretty special about lists is the amount of functions built just for them, there is ones to remove items, ones to add items, and ones to read the list and stuff. Before we go over those functions lets go over making lists and changing them using =

list = [1,2,3,4,5]
print(list[0])
list[0] = "This is not a number"
print(list[0])

What happened in that last example was we had a list with some numbers, then we printed the first item(remember python starts counting at 0 with lists), then we changed the first item and printed it again(to show it changed)

The issue with changing items this way is you cant add items, usually this isnt really a problem but sometimes you need to add/remove items. The next thing we will look at real quick will be putting lists into lists

list = [1,2,["notNumber1","notNumber2","notNumber3"],3,4]
print(list[0])
print(list[2][0])
print(list[2][2])
print(list[3])

what we did in that example was make a list where the 3rd (referenced with 2) item in our list is a list, then to pull from that list we tell it which item we want then witch item in that list we want. And thats really all for this subsection, now we will move on to a lists functions. See you then!

Adding and changing list items with functions.

So in this subsection we will go over adding new items, and changing old ones in a list. The first function we will go over is the .apphend() function. The .Apphend() function just adds an item to the end of a list

list = [1,2,3,4]
print(list)
list.append("wow another item!")
print(list)

Removing items from lists and sorting lists

In this subsection we will learn how to remove items from lists and how to sort our lists into alphabetical order. starting with removing items, to do this you just use the del() function like so:

list = [1,2,3,4,5]
print(list)
del(list[1])
print(list)

If you run this code you will se before we delete item two our list is 1,2,3,4,5 but after it is 1,3,4,5. showing that we succsesfully removed an item from our list

Functions

In this section we will go over what a function is, how to make one, and how to use it.

What a function is, and how to make it

A function is a block of code you make once then can call later with a single function, for example if you needed to do 5 if statements to check variables often you would use a function. Here is an example on how to make a function

def helloworld():
  print("hello world")

In this example if we ever put "helloworld()"(not in quotations) in our code it will run the code saved to it. and our function can be named anything we want, it doesnt have to be named helloworld. and we can put any code we want inside it it doesnt have to be a print. one thing we have to remember is if we want to use variables outside and inside a function we need to declare them outside of it and then do this inside it:

name = "bob"
      
def hello()
  global name
  print("hello "+name)