0

What's the mistake with this code?

This code give the sum of N numbers N = int(input()) #your code goes here Z=range (N) x=0 for i in Z : x=x+i print (x)

30th Sep 2021, 9:30 AM
Afnan Eljak
4 odpowiedzi
+ 5
Z=range (N+1)
30th Sep 2021, 9:33 AM
Simba
Simba - avatar
+ 1
It should be something lile this: N = int(input()) x = 0 for i in range(N+1): x += i print(x)
30th Sep 2021, 9:32 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 1
Thanks all🥰
30th Sep 2021, 9:36 AM
Afnan Eljak
0
n = int(input()) Mathematical Solution Ans= n*(n+1)/2 Brute forcing Ans = sum(range(n+1))
1st Oct 2021, 8:28 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar