1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dmitriy555 [2]
2 years ago
6

a) Write a program that prompts for an integer—let’s call it X—and then finds the sum of X consecutive integers starting at 1. T

hat is, if X=5, you will find the sum of 1+2+3+4+5=15.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:1 = 11+2 = 31+2+3 =61+2+3+4 =101+2+3+4+5 =15Print only each sum, not the arithmetic expression.
Computers and Technology
1 answer:
Alex73 [517]2 years ago
7 0

Answer:

<u>Solution a</u>

  1. n = int(input("Enter an integer: "))
  2. sum = 0
  3. for x in range(1, n+1):
  4.    sum += x  
  5. print(sum)

<u>Solution b</u>

  1. n = int(input("Enter an integer: "))
  2. for a in range(1, n + 1):
  3.    sum = 0
  4.    for x in range(1, a+1):
  5.        sum += x
  6.    print(sum)

Explanation:

Solution code is written in Python 3.

<u>Solution a</u>

First get the user input for an integer (Line 1).

Create a variable sum and initialize it with zero value (Line 3).

Create a for loop to traverse through the number from 1 to integer n (inclusive) and sum up the current number x (Line 5-6).

Print the sum to terminal (Line 8).

<u>Solution b</u>

Create an outer for loop that traverse through the number from 1 to integer n (inclusive) (Line 3).

Create an inner loop that traverse through the number from 1 to current a value from the outer loop and sum up the current x value (Line 5-6).

Print the sum to terminal (Line 7) and proceed to next iteration and reset the sum to zero (Line 4).

You might be interested in
Is iPhone better than android
andriy [413]

Answer:

It's up to personal preference.

Explanation:

iPhone/Apple gives more compliments to security than Android.

Android has more friendly user GUI and dev tools.

4 0
2 years ago
Read 2 more answers
An open system consists of nonproprietary hardware and software based on publicly known standards that allows third parties to c
kolezko [41]

Answer:

The answer is "Option D".

Explanation:

A system or a group of components that communicate with your environment through the sharing of resources, materials, and knowledge with a view to system regeneration and development is known as an Open system. In other words, we can say that it is a system that includes a non-proprietary hardware and advert-based software which enables third parties to add or interact with products to plug in the system and It is freely available on the internet. In this question, the incorrect options can be described as follows:

  • In option A, The management system is used by an organization. It is a paid system that's why it is not correct.
  • In option B, This system enables users in online communities and evaluates one another that's why it is not correct.
  • In option C, This type of system provides resources for upgrade user knowledge. It is a paid system that's why it is not correct.  

6 0
2 years ago
Select the correct answer.<br><br> Which statement is true with respect to Java?
NARA [144]

Answer:

where are the options ..... to select

7 0
2 years ago
The following program draws squares recursively. Fill in the missing code. import javax.swing\.\*; import java.awt\.\*; public c
ExtremeBDS [4]

Answer:

The missing code to this question is g.

Explanation:

In this question firstly import packages. Then declaration of the class Test that inherits the JApplet. In this class, we declare the default constructor. In this constructor, we call the add function. Then we declare another class that is SquarePanel. This class inherits JPanel. In this class, we define a method that is paintComponent(). In this method, we define an integer variable. In this method, we perform calculations and pass it to another function that is displaySquares(). In this function, we pass the value as the arguments. So in question the missing code or argument is g.

8 0
3 years ago
The most distinctive feature of Google+ is
klio [65]
The answer is B, circles
8 0
3 years ago
Other questions:
  • What is html?
    9·2 answers
  • I'm the state of Florida, your first conviction for DUI can result in your vehicle being impounded for
    5·1 answer
  • ​User documentation _____. Group of answer choices ​allows users to prepare overall documentation, such as process descriptions
    9·1 answer
  • Danica is creating a flyer for her cookies that she will sell during her school fair. She wants to add a registered
    7·1 answer
  • Which objects appear on the slide after she clicks OK? Check all that apply.
    13·1 answer
  • a pair of shoes is on sale for 15% off with this discount customers will pay $9 if they buy the shoes ​
    14·1 answer
  • An enhancement to a computer accelerates some mode of execution by a factor of 10. The enhanced mode is used 50% of the time, me
    11·1 answer
  • Question 8 (True/False Worth 3 points)
    15·1 answer
  • For a parking application that lets you pay for parking via your phone, which of these is an example of a functional requirement
    8·1 answer
  • 15. You read a news article that's politically biased and not well organized. It's
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!