ListofPeople = ["John", "Advay", "Grant", "William"]
for person in ListofPeople:
if len(person) < 5:
print(person)
Explanation
Everything is Sequencing.
for person in ListofPeople
is iteration, as it iterates over the set list of names.
if len(person) < 5:
is selection, as it selects for a name with less than 5 letters.
for i in range(5):
if i % 2 == 1:
print(3)
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
Video 2
- Find the value for a, b, c, d
- a = 1, b = 7, c = 3, d = 7
- What are the values of hot and cold after executing the code segment?
- Hot = true, cold = true
{
a = 1
b = 2
c = 3
d = 4
e = 5
f=(a+b+c+d+e)
result = f
display(result)
}
Answer: 15 because 1+2+3+4+5=15.
{
a = 2
b = 4
c = a*b
d = a*b*c
e = (a+b+c+d)/(d-b)
display(e)
}
Answer:
c = 8
d = 64
e = 2+4+8+64/(6-2) = 78/4 = 19.5
because based on the values of a and b, c must be 24=8, d must be 24*8=64. By finding the values of A,B,C, and D we can then calculate the value of E.