+ 3
How do I get total sum of range?
Number = input("Enter any number you like between 0-10") Sum = 0 for i in range(11): total = number + i Print(total) Please help! Thanks!
9 Antworten
+ 8
Actually:
print(sum(range(int(input("Enter no.")))))
# that will do the trick, too
+ 1
Strange... I don't have any syntax error. Here is the code:
https://code.sololearn.com/cWrj2CuqFfba/?ref=app
+ 1
That's just to print a new line.
Glad to know that you understand. Keep coding :)
0
Your logic is not correct. It will be something like this:
Number = int(input("Enter any number you like between 0-10"))
Total = 0
for i in range(Number+1):
Total = Total + i
print()
print(Total)
0
First you need to convert the input into integer. Then run the loop from 0 upto the Number.
Here 'for i in range(x)' means value of i will be 0, 1, 2,...., (x-1). Moreover you don't need sum when you are doing your calculations using 'Total'.
Here initial value of Total will be 0. And inside loop you are adding up the value until a certain range(Number between 0 and 10) given by the user.
Also you need to intend the statement after ':' to make the compiler understand that it is inside for loop. It is a basic syntax of python.
0
Thanks! There is a invalid syntax on Total = 0
0
I appreciate the help! I didn't add the print()
0
Simple basic Maths
n = int(input('Enter any number'))
print((n*(n+1))/2)
0
i have noticed that the p on print is capital so maybe that is another part of the problem