- 2

fib = {1:1,2:1,3:2,4:3} print(fib.get(4,0)+fib.get(7,5))

Why this doesn't work

11th Nov 2016, 2:41 AM
Md Jabed Hossain
Md Jabed Hossain - avatar
20 ответов
+ 31
in this (4,0), 4's value is 3 as given in fib now look at (7,5)..here 7 is not in fib so by default it (get) will take 5.. so now the addition of 3+5=8,so our output is 8.
15th Jan 2017, 10:53 AM
Pragya Priya
Pragya Priya - avatar
+ 8
if the number before the comma is not in the dictionary then number after the comma is taken default 7,5 in this 7 is not in the dictionary so 5 is taken
27th Dec 2016, 3:29 AM
Abhilash rao Badguna
Abhilash rao Badguna - avatar
+ 7
You do not enter an indent in the beginning of second line, try this: fib = {1:1,2:1,3:2,4:3} print(fib.get(4,0)+fib.get(7,5)) #output = 8
15th Nov 2016, 9:46 PM
Dehron
Dehron - avatar
+ 3
5 got it because it is indicated, if the dictionary does not have the first value, what is indicated is displayed on the screen, separated by commas ) And it turns out that we do not have the first value (7), which means that what is indicated is displayed separated by commas (5) hence comes: 5 + 3 = 8
16th Jul 2020, 2:53 PM
Alexandr Kovernyk
Alexandr Kovernyk - avatar
+ 3
So, what I've understood from this in simple English fib = {1:1, 2:1, 3:2, 4:3} print(fib.get(4,0) + fib.get(7,5)) the answer is 8. Let me explain fib.get(4,0) is 3 because 4 is on the 3rd dictionary of fib (remember you start counting from 0) which means 1:1 is 0, 2:1 is 1, and so on. (7,5) is not in the dictionary, so, the second value is taken by default, which also means automatically 5 is taken. Now adding their results, we have 3 + 5 =8
10th Sep 2022, 10:31 AM
Victor Mbukpa
Victor Mbukpa - avatar
+ 1
remove the space at the beginning of the second line as in, fib = {1:1,2:1,3:2,4:3} print(fib.get(4,0)+fib.get(7,5)) result is 8
11th Nov 2016, 8:12 AM
Sunera Avinash
Sunera Avinash - avatar
+ 1
Can anyone how it works and let me know the logic
6th Dec 2016, 6:14 PM
Biswascoder
Biswascoder - avatar
0
except indebted
14th Nov 2016, 11:42 AM
ling gan
ling gan - avatar
0
I don't understand why or how the value 5 is in place.
22nd Nov 2016, 2:48 AM
Dillon Ko
Dillon Ko - avatar
0
8
26th Oct 2018, 3:51 PM
Houcem Eddine Aouissaoui
Houcem Eddine Aouissaoui - avatar
0
I don't fully comprehend the logic behind the addition of 5
1st Apr 2020, 7:49 AM
MELULEKI MINENHLE KHWELA
0
get cancer whoever made this app
24th Dec 2020, 10:50 AM
B44
B44 - avatar
0
its 8
24th Mar 2021, 6:39 PM
Sophia Porras
Sophia Porras - avatar
0
fib = {1: 1, 2: 1, 3: 2, 4: 3} print(fib.get(4, 0) + fib.get(7, 5)) fib.get(4,0) its return value 3 (# 4th value) fib.get(7,5) its retturn value 5(# specified value) the key is not found in the dictionary it returns another specified value print(fib.get(4, 0) + fib.get(7, 5)) print(3+5) print(8)
11th Oct 2021, 1:01 PM
Pratap Vasava
Pratap Vasava - avatar
0
8
8th Jul 2022, 12:58 PM
Lethabo Mokgokoloshi
Lethabo Mokgokoloshi - avatar
0
8
21st Jul 2022, 1:37 PM
wessam lahmod
0
fib = {1: 1, 2: 1, 3: 2, 4: 3} print(fib.get(4, 0) + fib.get(7, 5)) print(fib.get(4, 0)) this line output is three because it takes the value of key 4. Where as print(fib.get(7, 5)) this one out put is 5 because there is no any any number with the key 7. So it takes its value 5 by defualt
9th Nov 2022, 11:47 AM
ISMAEL YIMAM MOHAMMED
ISMAEL YIMAM MOHAMMED - avatar
0
8
28th Oct 2023, 4:33 AM
Dharani
Dharani - avatar
0
fib = {1: 1, 2: 1, 3: 2, 4: 3} print(fib.get(4, 0) + fib.get(7, 5))
16th Nov 2023, 8:39 AM
sahar samie
sahar samie - avatar
- 1
Still don't get how 5 is in
30th Dec 2016, 1:34 PM
Chiara Fanelli
Chiara Fanelli - avatar