IKH

Practice Question

Example

Python
def countdown(num):
  print("Start Countdown")
  while(num>0):
    yield num
    num=num-1

values=countdown(5)
for x in values:
  print(x)

Output

PowerShell
Start Countdown
5
4
3
2
1

Example

Python
def firstn(num):
  n=1
  while n<=num:
    yield n
    n=n+1

values=firstn(5)
for x in values:
  print(x)

Output

PowerShell
1 
2 
3 
4 
5

Example

Python
def fib():
  a,b=0,1
  while True:
    yield a
    a,b=b,a+b

for f in fib():
  if f>100:
    break

print(f)

Output

PowerShell
144

Example

Python
def fib():
  a,b=0,1
  while True:
    yield a
    a,b=b,a+b
for f in fib():
  if f>100:
    break
  print(f)

Output

PowerShell
0
1
1
2
3
5
8
13
21
34
55
89

Ungraded Questions

Get ready for an exhilarating evaluation of your understanding! Brace yourself as we dive into the upcoming assessment. Your active participation is key, so make sure to attend and demonstrate your knowledge. Let’s embark on this exciting learning journey together!

Report an error