[Type C]Q7. Write a program that reads an integer N from the keyboard, computes it, and displays the sum of the numbers from N to(2N) if N is non-negative. If N is a negative number, then it’s the sum of numbers from(2N) to N. The starting and ending points are included in the sum.

If-Else syntax:

if (condition):
elif (condition):

If else flowchart:


Program code:


Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Enter an Integer: 5 

An input of integer is taken from user.

If the input is positive, a for loop is initiated for range of entered integer and its double. The sum is calculated for all numbers between the specified range.

If the input is negative the range is reversed and sum is printed.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-1/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page