- 2
fib = {1:1,2:1,3:2,4:3} print(fib.get(4,0)+fib.get(7,5))
Why this doesn't work
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.
+ 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
+ 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
+ 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
+ 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
+ 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
+ 1
Can anyone how it works and let me know the logic
0
except indebted
0
I don't understand why or how the value 5 is in place.
0
8
0
I don't fully comprehend the logic behind the addition of 5
0
get cancer whoever made this app
0
its 8
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)
0
8
0
8
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
0
8
0
fib = {1: 1, 2: 1, 3: 2, 4: 3}
print(fib.get(4, 0) + fib.get(7, 5))
- 1
Still don't get how 5 is in