0

Почему 6?

def func (x): res=0 for i in range (x): res+=i return res print(func(4))

6th Feb 2020, 7:09 AM
Krasavchik Gara
Krasavchik Gara - avatar
1 Resposta
+ 2
range(4) is 0, 1, 2, 3 so res = 0 + 0 = 0 0 + 1 = 1 1 + 2 = 3 3 + 3 = 6 so returned 6
6th Feb 2020, 7:11 AM
Gordon
Gordon - avatar