Previous Lesson Current Lesson Next Lesson

# Question 1

for i in range(5, 11):
print(i / 10)


This will output:

0.5
0.6
0.7
0.8
0.9
1.0


Note that we use 11 as the end input to range because we iterate from 5 to end - 1. Thus, we iterate over the values from 5 to 10 inclusive.

# Question 2

def f(n):
for i in range(1, n + 1):
yield i * i


Note that we use n + 1 as the end input to range because we iterate from 5 to end - 1. Thus, we iterate over the values from 1 to n inclusive.

Note the important yield keyword to create a generator out of this function!