Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:53:00+00:00 2026-06-18T05:53:00+00:00

Here is my original code: x = input(Please input an integer: ) x =

  • 0

Here is my original code:

x = input("Please input an integer: ")
x = int(x)
i = 1
sum = 0
while x >= i:
    sum = sum + i
    i += 1
print(sum)

Here is what the second part is:

b) Modify your program by enclosing your loop in another loop so that you can find consecutive sums. For example , if 5 is entered, you will find five sum of consecutive numbers so that:

1 = 1
1 + 2 = 3
1 + 2 + 3 = 6
1 + 2 + 3 + 4 = 10
1 + 2 + 3 + 4 + 5 = 15

I have been stuck on this for 3 days now, and I just can’t understand how to do it. I have tried this but to no avail.

while x >= i:
    sum_numbers = sum_numbers + i
    past_values = range(i)
    for ints in past_values:
        L = []
        L.append(ints)
        print(L, "+", i, "=", sum_numbers)
    i += 1

Can anyone just help steer my in the correct direction? BTW. it is python 3.3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:53:01+00:00Added an answer on June 18, 2026 at 5:53 am

    You could do this in one loop, by using range to define your numbers, and sum to loop through the numbers for you.

    >>> x = input("Please input an integer: ")
    Please input an integer: 5
    >>> x = int(x)
    >>>
    >>> for i in range(1, x+1):
    ...     nums = range(1, i+1)
    ...     print(' + '.join(map(str, nums)), '=', sum(nums))
    ...
    1 = 1
    1 + 2 = 3
    1 + 2 + 3 = 6
    1 + 2 + 3 + 4 = 10
    1 + 2 + 3 + 4 + 5 = 15
    

    range(1, x+1) would give me [1, 2, 3, 4, 5], this acts as the controller for how many times we want to print out a sum. So, this for loop will happen 5 times for your example.

    nums = range(1, i+1) notice we are using i instead here, (taken from the range above), which I am using to define which number I am up to in the sequence.

    ' + '.join(map(str, nums)):

    • map(str, nums) is used to convert all elements of nums into strings using str, since the join method expects an iterable filled with strings.
    • ' + '.join is used to “join” elements together with a common string, in this case, ‘ + ‘. In cases where there is only 1 element, join will just return that element.

    sum(nums) is giving you the sum of all numbers defined in range(1, i+1):

    • When nums = range(1, 2), sum(nums) = 1
    • When nums = range(1, 3), sum(nums) = 3
    • Etc…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is the original code: public static int getInt () { Scanner in =
I'm porting a C# Library to Java (for nonlinear regression, original code here ).
Here is the original code of Visual C++ which I have been trying to
###########Update Here is the original code that worked in ie7 but not in 9.
Here was my original code: #include <stdio.h> #define IN 1 // inside a word
Here's the code for my original PHP code: public function outputText() { $i =
Here is original Query :, it generates o/p with two columns name (label, count)
here is my original function. it works perfectly, I just want to compress it
Refer original post here for a reference to the original issue. What plugin should
Let's say I have some original text: here is some text that has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.