+ 5

Why it's not working!?

I am doing that test when they ask to write a program that can print the sum of a number soo I just did N=int(input ()) Print (sum(range(N+1))) This code work so fine in my visual studio code But here it doesn't accept it It's gives an error Can someone explain why

5th Sep 2021, 1:06 PM
Youcef Tahri
23 ответов
+ 2
Test case passes without making list explicitly
5th Sep 2021, 1:53 PM
Sacar
Sacar - avatar
+ 2
Yes For example Let's take 100 as an input The output should be the sum of the numbers from 1 to 100 So the output is 5050
5th Sep 2021, 1:17 PM
Youcef Tahri
+ 2
Fariha💕 Sacar Guys go to python for beginners project 36 And try my code
5th Sep 2021, 1:30 PM
Youcef Tahri
+ 2
Your second line of code produces error, Because your "P" of print is capital. It should be small "p". Change this and your program will run Fine.
6th Sep 2021, 5:27 AM
Kartikey Kumar
Kartikey Kumar - avatar
+ 2
Saif Al-Hussain you can import math module and use floor() function like: import math n = int(input()) sum = n*(n + 1) / 2 sum = math.floor(sum) print(sum) But it's Bs!
7th Sep 2021, 8:52 AM
Sacar
Sacar - avatar
+ 1
Hey Fariha💕 thanks for trying to help me but still not working
5th Sep 2021, 1:11 PM
Youcef Tahri
+ 1
Your code should work already ..
5th Sep 2021, 1:21 PM
Sacar
Sacar - avatar
+ 1
Sacar Well yes But in the test it still gives an error of unexpected end_of_cod
5th Sep 2021, 1:24 PM
Youcef Tahri
+ 1
Fariha💕 nah the test still doesn't expect it as correct answer
5th Sep 2021, 1:26 PM
Youcef Tahri
+ 1
What kind of test are you performing ? If you could show us the question...
5th Sep 2021, 1:28 PM
Sacar
Sacar - avatar
+ 1
Here's what i had done : N = int(input()) nums = list(range(1, N+1)) print(sum(nums))
5th Sep 2021, 1:33 PM
Sacar
Sacar - avatar
+ 1
Thank you so much Fariha💕 and Sacar It's works now but the problem is my code do the exact same what your code do but mine is shorter why it didn't work ಥ╭╮ಥ
5th Sep 2021, 1:36 PM
Youcef Tahri
+ 1
I really understand what you are saying What I don't understand why the test didn't expect my code even it do the same thing as your
5th Sep 2021, 1:51 PM
Youcef Tahri
+ 1
Oh I got it now thank you
5th Sep 2021, 1:55 PM
Youcef Tahri
+ 1
Copy paste this: n = int(input()) print(sum(range(n+1)))
5th Sep 2021, 1:56 PM
Sacar
Sacar - avatar
+ 1
N= int(input) total = list (range(N+1)) print(sum(total)
6th Sep 2021, 4:57 PM
Sachin Yadav
Sachin Yadav - avatar
+ 1
Perhaps that's because you have to import a library or a module
7th Sep 2021, 8:13 AM
Saif Al-Hussain
Saif Al-Hussain - avatar
0
No I believe the test will only pass by just making a list
5th Sep 2021, 1:58 PM
Youcef Tahri
0
This is the best one n = int(input()) print(n * ( n+1 ) / 2)
5th Sep 2021, 8:20 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
0
Where is the question
6th Sep 2021, 9:41 PM
Ushow May
Ushow May - avatar