3.3 Example #1

print("Hello")
for i in range(10):
    print(i) if (i**2 % 2 == 0) else print("bummy num")
Hello
0
bummy num
2
bummy num
4
bummy num
6
bummy num
8
bummy num

Explanation

  • Everything is sequencing
    • for i in range(10) is iteration, as it iterates over the iterable object returned by the range function.
    • `print(i) if (i2 % 2 == 0) else print("bummy num")`** is selection, as it selects when to print i

3.3 Example #2

for letter in "TeAmBrObRo":
    print(letter) if letter.islower() else letter.isalnum
    
e
m
r
b
o

Explanation

  • Everything is sequencing
    • for i in range(5) is iteration, as it iterates over the range [1,5].
    • if num % 2 == 1 is selection, as it selects for a odd number

3.3 Video #2 HW

  1. Find the value for a, b, c, d
  • a = 1, b = 7, c = 3, d = 7
  1. What are the values of hot and cold after executing the code segment?
  • Hot = true, cold = true

3.3 Code Segments

{
a = 1
b = 2
c = 3
d = 4
e = 5

result = a MOD b MOD c MOD d MOD e 
display(result)
}

Answer: 1 mod 2 mod 3 mod 4 mod 5 = 1

{
    a = 1
    b = 2
    c = a+b
    d = a+b+c
    e = (a+b+c+d)/(d-b)
    display(e)
}

Answer:

c = 3
d = 6
e = 1+2+3+6/(6-2) = 12/4 =
3

3.4 HW

  1. SmithB@gmail.com
  2. ompuook