slatt language 🐍,

pc: https://cdn.dribbble.com/users/1772963/screenshots/5621796/python_4x.png

This is about school. Promise .
We started a new programming language. Python to be exact. It is a direct language, does not have a lot of semantics. Founded in the 80’s by a Guido Van Rossum, then wikipedia author starts to get technical about it. Seriously. Check it.

This is an intro to Python, nimbly chronicled by me:

What is Python?

  • This is a high-level programming language.

To me it means we just write less constructed code. Easier for us to understand than the machine. Low-level is the opposite ,easier for the machine to understand , thus more — structured? to us.

  • It is a multi-purpose language, meaning that it can and is used in almost every aspect of prgramming.
  • The popular application among others is Data Science. Reason as to why is Python has an in-built math() libary that can compute to the last decimal.
    It also has functions that perform algebraic expressions/operations.
  • Versions — Python 2.7 which was widely used for some time but now its Python 3.

Data Types and Variables

I do not think data types vary among programming languages. We can group them to three:

  1. Numbers.
    - There are integers ,floating numbers, complex numbers.
    - Integers are (+/-) whole numbers.
    - Floating numbers are (+/-) decimal numbers.
    - Complex numbers is (real , imaginary) numbers.
complex (real, imaginary)
print(complex(10, 20)) # Represents the complex number (10 + 20j)

In normal mathematics, the imaginary part of a complex number is denoted by i(integer i)
However, in the code above, it is denoted by j.
This is because Python follows the electrical engineering convention which uses j instead of i.

2. Strings
- This is a set of characters that is enclosed in ‘ ’, “ ” or ‘’’ ‘’’.
- It can also be empty.
- There are several string -functions**These are[ indexing, slicing, reverse indexing, search]
- There is string formatting.This means substituting values into a string, by insertion of strings, floats and integers into the said string.

3. Booleans
- Okay this is the data type with two values only. (True and False)

Operators are : Arithmetic ,Assignment ,Bitwise, Comparison, Logical.

Functions

This is how we tell our program to do something, but alas! We have to write some lines of code in order for it to actually do something.

meme generated by me:)
  • It is a set of reusable operations. Like talking a walk.
  • We have to take step a and then step b repeatedly to finish our walking operations.
function walk(step a, step b){
return step a + step b;
}
print(walk()); //anytime you run the walk function the process will take place.

Conditional Statements.

Here is where things get, flat. No. Plain.
Indentation is important in python . I suggest use the tab-tab when writing code.
I’ll just write a code snippet** for all. You can run them here to see the results.
The conditional statements in python are if, if-else, if-elif-else.

  • if statement
num = 5  if (num == 5):  # The condition is true     
print("The number is equal to 5") # The code is executed

if num > 5: # The condtion is false
print("The number is greater than 5") # The code is not executed
  • if-else
num = 60
if num <= 50:
print("The number is less than or equal to 50")
else:
print("The number is greater than 50")
  • if-elif-else
light = "Red"if light == "Green":
print("Go")
elif light == "Yellow":
print("Caution")
elif light == "Red":

print("Stop")
else:
print("Incorrect light signal")

Loops

  • Now remember our walk(). That is a set of reusable code. Which is good cause what if God made walk() each time He created a human being? Tiresome.

That’s why He made the walk() function iterate for an nth- being born , unless ofcourse an asteroid hits us. again. Then the walk () stops. Aaaanywaaays,

  • Loops come in to perform a set of instructions(functions) a stated number of times.
    The thing it does is that it iterates the function a number of times until that specification is met.
  • There are two types of loops:( for loop, while loop)
    1.for loop
    - this is a type of iterator that goes through things in a list.
    - it starts with a for
for iterator in sequence:
operations
for i in range(1, 11, 3):
print(i)
1 - is our starting point
11 - is our end point
3 - is delimiter
** the third option is not a must sometimes unless you want to state how you want your loop to traverse.- So we just said we want a loop that prints an integer that starts from 1 to 11 (but exclude 11) in steps of 3.//OUTPUT
1 4 7 10

2. while loop
- This perfoms a set of operations as long as the condition is True. It has no limits unless otherwise.
-
I believe a more practical example is withdrawal & overdrafting.

You can withdraw x (amount of money) from your bank account n (number of times) as long as you have money.
The process stops when the condition (having money) is now False hence overdraft.

Correct me if I am wrong.

Keywords used in loops. — (from my understanding)

Break — this stops the loop when the first condition is met. It ends the operation there and then . Does’nt care about the rest.
The walk() can be made such that if you find a puddle, you turn around and go home.

Continue — — In walk(), you jump it and continue walking.

We will break for now

This post has been long overdue. I will continue as we have learnt other things.We did a paired project of creating a (Simple) Unix Shell . They called it Simple Shell but I paranthesised it cause.

Commit count : 772

Oh, I also learnt how to do a pull request. I’m proud of that.

And a few ⌨ shortcuts :
(Ctrl + /) — this will comment any code you highlight.
Windows Home Logo + period (.) — will bring up the emoji ⌨ and you can choose.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store