+ 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
23 Antworten
+ 2
Test case passes without making list explicitly
+ 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
+ 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.
+ 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!
+ 1
Hey Fariha💕 thanks for trying to help me but still not working
+ 1
Your code should work already ..
+ 1
Sacar
Well yes
But in the test it still gives an error of unexpected end_of_cod
+ 1
Fariha💕 nah the test still doesn't expect it as correct answer
+ 1
What kind of test are you performing ? If you could show us the question...
+ 1
Here's what i had done :
N = int(input())
nums = list(range(1, N+1))
print(sum(nums))
+ 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
+ 1
Oh I got it now
thank you
+ 1
Copy paste this:
n = int(input())
print(sum(range(n+1)))
+ 1
N= int(input)
total = list (range(N+1))
print(sum(total)
+ 1
Perhaps that's because you have to import a library or a module
0
No I believe the test will only pass by just making a list
0
This is the best one
n = int(input())
print(n * ( n+1 ) / 2)
0
Where is the question