- 1

What does the "for" loop do?

w = int(input()) h = float(input()) bmi = w/(h**2) dic = { "Underweight" : lambda v: v < 18.5, "Normal" : lambda v: 18.5 <= v < 25, "Overweight" : lambda v: 25 <= v < 30, "Obesity" : lambda v: 30 <= v < 100, } for res in dic: if dic[res](bmi): print(res) break

27th Feb 2021, 7:54 PM
Sadra Shakouri
Sadra Shakouri - avatar
3 Answers
+ 3
the for loop iterate over dict and call each 'anonymous' (lambdas) function... if result is true, print the key, and stop the loop
27th Feb 2021, 7:57 PM
visph
visph - avatar
0
visph thanks
27th Feb 2021, 7:58 PM
Sadra Shakouri
Sadra Shakouri - avatar
- 1
visph can you help?
27th Feb 2021, 7:55 PM
Sadra Shakouri
Sadra Shakouri - avatar