didnt understand this code | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

didnt understand this code

fib = {1: 1, 2: 1, 3: 2, 4: 3} print(fib.get(4, 0) + fib.get(7, 5)) ans is 8 but how ??

14th Aug 2020, 5:07 PM
Rohit Mahajan
Rohit Mahajan - avatar
1 Respuesta
+ 8
the answer is like this: fib.get(4,0) returns 3, as this is the value for key 4 fib.get(7,5) returns 5, as there is no key with this value. the second parameter is a value that will be used, in case key is not found finally add 3 + 5 so you get 8
14th Aug 2020, 5:15 PM
Lothar
Lothar - avatar