0

Can someone explain how the result is 6 ??

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

21st Jul 2023, 11:43 AM
احمد حافظ احمد عبدالله عبدالرحمن
احمد حافظ احمد عبدالله عبدالرحمن - avatar
1 Resposta
+ 6
عثمان محمد ابراهيم. Note that use relevant tags instead of `u`. this is python program so this is best way if you Use python instead of `u` We get `6`. This is because the sum of all the numbers from 0 to 3 is 6 (0 + 1 + 2 + 3 = 6). However, there is a mistake in this code. For fix the issue change `res+=i` instead of`res +-i`.
21st Jul 2023, 12:11 PM
Darpan kesharwani🇮🇳[Inactive📚]
Darpan kesharwani🇮🇳[Inactive📚] - avatar