55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
# This will show some very basic Python operations and actions
|
|
|
|
# We show output in the terminal to a user with the "print" function
|
|
print("Hello world!")
|
|
|
|
# This is a variable. A variable holds information like a string (letters and such),
|
|
# integers (whole numbers), arrays and objects (discussed later)
|
|
# Our first "string"
|
|
name = "Computer User"
|
|
# We can print many things in one print command on one line by
|
|
# separating them with commas
|
|
print("Your name is:", name)
|
|
|
|
# Our first number
|
|
# The "=" here is an "assignment operator"
|
|
# meaning "assign the value on the right to the variable on the left"
|
|
# (i.e. assign age equal to 32)
|
|
age = 32
|
|
print("Your age is:", age)
|
|
|
|
# Basic math:
|
|
# Python includes math operators for addition, subtraction,
|
|
# multiplication and division (and many others).
|
|
age = age + 1
|
|
# Age is now equal to 33
|
|
# Someone had a birthday!
|
|
print("Happy Birthday! You are now", age, "years old!")
|
|
|
|
# Simple math operators can be combined for the sake of brevity.
|
|
# These are called "compound" operators
|
|
# age = age + 1
|
|
# is the same as
|
|
# age += 1
|
|
#
|
|
# Basic compound operators: += -= *= /= (/= is a floating point operator)
|
|
# (A special //= which returns integer)
|
|
unused_age = 100
|
|
print(f"Unused Age: {unused_age}")
|
|
unused_age -= 1 # unused_age is now 99
|
|
print(f"Unused Age: {unused_age}")
|
|
unused_age += 3 # unused_age is now 102
|
|
print(f"Unused Age: {unused_age}")
|
|
unused_age *= 4 # unused_age is now 408
|
|
print(f"Unused Age: {unused_age}")
|
|
unused_age //= 2 # unused_age is now 204
|
|
print(f"Unused Age: {unused_age}")
|
|
|
|
# There is a common operator used in programming called the "modulo" or "modulus".
|
|
# This operator is a division operator that returns the remainder after
|
|
# the division is complete.
|
|
unused_age %= 100
|
|
print(f"Unused Age: {unused_age}")
|
|
|
|
|