Q. Write a program that reads an integer N from the keyboards computes and displays the sum of numbers from N to (2*N) if N is nonnegative. If N is a negative number, then it’s the sum of the numbers from (2*N) to N. the starting and ending points are included in the sum.
You can understand by Watching video :-
Answer :-
sum = 0 n = int(input("Enter the number :-")) if n > 0 : for i in range (n,n*2+1): sum += i else : for i in range (2*n, n+1): sum += i print (sum)
Output :-
Enter the number :- 10
165
>>>
Enter the number :- -10
-165
>>>
Enter the number :- 95
13680
>>>
Enter the number :- -754
-853905
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )