Home Python

Welcome to the Python Projects Page

We make coding content to show what’s happening behind the scenes in electronics...

Python is a coding language used to make programs (apps). To print (write):

print('hello')


To make an input (ask), there are two ways:

Way number one:

input("What is your name?")

This way can't be used in an if statement

Way number two:

i = input("What is your name?")

This way can be used in an if statement

Talking about if statements, here's how to write one:

i = int(input("How old are you? "))
if i >= 18:
    print("You fit in our company terms and conditions!")
else:
    print("You don't fit in our company's terms and conditions, so you can't create an account!")
            

Data types

To write a string (str), which means text values:
name = "Ali"
age = "15"
print(name)
print(age)
(The name you put before the equal sign is called a variable, and you can name it anything as long as you haven't used that exact name before in the same scope.)
is_student = "True" To write Integers (negative and positive numbers) write:
number_of_students = 10
speed = -120
print(number_of_students)
print(speed)
How to write float (A number with decimals)
GPA = 3.5
bill = round(15.329, 2)
print(bill)
print(GPA)
To write a Boolean (which means True or False) write:
is_player = True
#or is_footballer = False
print(is_player)
print(is_footballer)
(The **hash symbol (#)** means the code following it is a comment, so the interpreter ignores it and it won't be seen when your app runs.) If you don't want to change its value (True or False) then write:
is_player = True
#or is_footballer = False
print(not is_player)
print(not is_footballer)

Math Equations

To make addition, write:
print(2+2)
#warning: do not use the equal sign here!
To do subtraction, write:
print(10-6)
To do multiplication, write:
(9*9)
#warning: using the letter 'x' instead of the asterisk (*) will not work.
Division
print(28/4)
#only use the slash sign
To do a Modulo, which means to ask what the remainder of the number is, write:
print(24%7)
To use comparison operators (==, !=, >, <, >=, <=) write:
print(1 == 1)
print(1 != 2)
print(1 > 2)
print(1 < 2)
print(1 >= 2)
print(1 <= 2)
("==" means equal to, "!=" means not equal to, ">" means greater than, "<" means less than, ">=" means greater than or equal to, and "<=" means less than or equal to.)