Skip to content

Latest commit

 

History

History

1-expressions-control-flow

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Monday - Expressions and Control flow

Reqiuired installs

Materials for this day

Must have

Nice to have

Workshop

Hello World

print('Hello world')

Numbers

1
0
123
-1
1.1
1.0

1 + 1
2 - 1
3 * 4
1 / 2
1 / 0
1 // 2
1 % 2
2 ** 10
(1 + 3) * 4

Variables

a = 1
a
a = a + 1
a += 1

Excercises

Boolean

a == 2
True
False
1 < 2
1 > 2
1 == 2
1 != 2
True or False
True and False
not True

type(1)
type(1 == 1)

Excercises

Strings

"alma"
""
type("alma")
"alma" + "fa"
"alma" - "fa"
"alma" + 3
"alma" + str(3)
"alma" * 3
"a" in "alma"
len("alma")
"alma"[1]
"alma"[1:3]
int("123")

Excercises

Arrays

[1, 2, 3]
[]
[1, 2] + [3]
[1] - [2]
[1, 2] * 3
1 in [1, 2]
len([1, 2, 3])
arr = [1, 2, 3]
arr[0]
arr[1:3]
[] is []

Excercises

None

None

If

if a == 2:
    print(a)


if a == 2:
    print("two")
else:
    print("other")


if a == 1:
    print("one")
elif x == 2:
    print("two")
else:
    print("a lot")

if a == 1:
    pass
else:
    print("not one")

Excercises

While

a = 0
while a < 5:
    a += 1
    print(a)

Excercises

For

for i in [1, 2, 3, 4]:
    print(i)

for i in range(0, 4):
    print(i)

Excercises

Please redo the While excercises with for

break & continue

numbers = [5, 7, 9, 11, 13, 12]

i = 0
while i < len(numbers):
    if numbers[i] % 3 != 0:
        pass
    else:
        print(numbers[i])
        break
    i += 1



numbers = [5, 7, 9, 11, 13, 12]

i = 0
while i < len(numbers):
    if numbers[i] % 3 != 0:
        continue
    else:
        print(numbers[i])
    i += 1