Characters

Letters that make up words.

Letters = ["a, b, c, d, e, f"]

print(Letters)
['a, b, c, d, e, f']

Strings

Sequence of characters that represent text.

strings = ["apple, samsung, windows"]

print(strings)
['apple, samsung, windows']

Length

The amount of characters in a string.

string = "HelloWorld"
x = string[0:8]
y = string[0:5]
z = string[5:8]
print(x)
print(len(string))
print(y)
print(z)
HelloWor
10
Hello
Wor

Concatenation

combination of strings to make sentences.

string1 = ("Hello how are you?")
string2 = ("Im good!")

print(string1, string2)
Hello how are you? Im good!

Traversing Strings

Iterate over the characters in teh string.

greeting = "Hello World"
for o in greeting:
    print(o)
H
e
l
l
o
 
W
o
r
l
d

Python if

An if statement is used when you want something to happen IF another thing has occurred.

x = 1

if x == 1:
    print("x is 1")
x is 1

Elif

It stands for else if, this is used when the first statement is false but you want to check for another condition.

price = 98343

if price > 100:
    print("price is greater than 100")
elif price == 100:
    print("price is 100")
elif price < 100:
    print("price is less than 100")
price is greater than 100

Else Conditional

This is used when the first statement is false so you want to run another statement.

hour = 19
if (hour < 18):
  greeting = ("Good day")
else:
  greeting = ("Good evening")

print (greeting)
Good evening

Nested selection statements

whenever selection statements are inside another selection statement.

hour = 19
if hour > 15:
    if hour == 15:
        print("it is 15 hours")
    elif hour == 16:
        print("it is 16 hours")
    elif hour == 17:
        print("it is 17 hours")
    elif hour == 18:
        print("it is 18 hours")
    elif hour == 19:
        print("it is 19 hours")
it is 19 hours

While loops with range

While loop is code that keeps running until a certain condition is met, the range would cause only the things in that range to print.

for num in range(1, 11):

    print(num)
1
2
3
4
5
6
7
8
9
10

With lists combining loops with conditionals to break

first create a list, then use a loop so it stops when it reaches a certain number in the list.

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

for number in numbers:
    if number == 7:
        break

print(number) 
7

Continue procedural abstraction

Variables are first defined, then later they are used again to solve the problem.

def multiply(x, y):
    return x * y

x = 3
y = 6

print(multiply(x, y))
18

python def procedures

allows you to define a procedure so you can use it more efficiently later on.

def multiply(x, y):
    return x * y

Parameters

Its a variable/placeholder for the values of a function.

def add(x, y): 
    return x + y # in this case the parameter is x and y

Return values

the value that function returns to when it wants to recall a variable.

def add(x, y):
    return x + y

x = 3
y = 6

print(multiply(x, y)) # recalls a variable previously defined

Simulation

Taking a process that exist in the real word and puts it in code format

def parse_input(input_string):
    if input_string.strip() in {"1", "2", "3","4", "5", "6"}:
        return int(input_string)
    else:
        print("Please enter a number from 1 to 6.")
        raise SystemExit(1)

import random

def roll_dice(num_dice):
    roll_results = []
    for _ in range(num_dice):
        roll = random.randint(1, 14)
        roll_results.append(roll)
    return roll_results


num_dice_input = input("How many dice do you want to roll? [1-6] ")
num_dice = parse_input(num_dice_input)
roll_results = roll_dice(num_dice)

print("you rolled:", roll_results) 
you rolled: [1, 13, 5, 10, 3]

Algorithm

step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output.

print("What Grade Did You Get?")
grade = int(input("Enter Grade:"))
if grade >= 93:
        print("Wow! Good job!")
if 70 <= grade < 93:
        print("Nice!")
elif grade < 70:
        print("Do Better")
What Grade Did You Get?
Do Better