0

Why this return makes invalid syntax?

def countdown(): i=5 while i > 8: print("i = {}".format(i)) yield i i -= 1 print(" =>i = {}".format(i) return i for j in countdown(): print(j)

12th Nov 2016, 4:02 AM
Xinyu Fang
Xinyu Fang - avatar
2 Respostas
+ 4
1) missing ) in line print(" =>i = {}".format(i) 2) you can't use return with a argument if you use that function as a generator so replace-> return i with-> yield I return so the code will be-> def countdown(): i=5 while i > 8: print("i = {}".format(i)) yield i i -= 1 print(" =>i = {}".format(i)) yield i return for j in countdown(): print(j)
12th Nov 2016, 4:35 AM
Sunera Avinash
Sunera Avinash - avatar
0
thanks
18th Nov 2016, 7:23 PM
Xinyu Fang
Xinyu Fang - avatar