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]
3 years ago
12

Ask the user to type in an integer greater than 50 and assign it to a variable called x. Write a program to calculate the sum of

squares of positive integers. The loop should stop when the sum is greater than x. At the end of the loop print how many numbers were used to calculate the sum. For example, if x is 100, sum will be 91, and six numbers (1 to 6) were used to calculate sum.
Computers and Technology
1 answer:
Zinaida [17]3 years ago
3 0

Answer:

The solution in Python is as follows:

<em>num = int(input("Number: "))</em>

<em>if num>50:</em>

<em>     sum = 0</em>

<em>     count = 0</em>

<em>     for i in range(1,num):</em>

<em>          count = count + 1</em>

<em>          sum = sum + i**2</em>

<em>          if sum > num:</em>

<em>               sum = sum - i**2</em>

<em>               count = count - 1</em>

<em>               break;</em>

<em>    </em>

<em>     print("Sum: "+str(sum))</em>

<em>     print("Numbers: "+str(count))</em>

<em>else:</em>

<em>     print("Number must be greater than 50")</em>

<em />

Explanation:

The condition stated in the question do not conform with the example. The question says, the loop should stop when sum > x.

But:

When x = 100 and sum = 91, the program loop should not stop because 91 is not greater than 100.

However, I'll answer based on the example given in the question.

This prompts user for number

num = int(input("Number: "))

The following if condition is executed if number is greater than 50

if num>50:

This initializes sum to 0

    sum = 0

This initializes count to 0

    count = 0

The iterates through the inputted number (e.g. 100)

    for i in range(1,num):

This increases the count

         count = count + 1

This calculates the sum of square of the positive integer

         sum = sum + i**2

The following removes excess number from the sum

<em>          if sum > num:</em>

<em>               sum = sum - i**2</em>

<em>               count = count - 1</em>

<em>               break;</em>

This prints the calculated sum    

    print("Sum: "+str(sum))

This prints the count of number used

    print("Numbers: "+str(count))

The following is executed if user input is less than 50

<em>else:</em>

<em>     print("Number must be greater than 50")</em>

<em />

<em></em>

You might be interested in
The human brain can store both temporary and permanent bits of information. Which type of memory in the computer is similar to t
aleksklad [387]

Answer:

RAM

Explanation:

"RAM" refers to <em>Random-Access Memory. </em>Just like the human brain, this stores your computer files temporarily. It is considered to be a <em>"volatile memory"</em> which means that information can only be stored<u> when there's power.</u> So, when your computer shuts down,<u> the information is los</u>t. This is similar to the human brain, especially when it comes to learning. When a person learns new things, some of the information he read before may be forgotten.

5 0
3 years ago
Please help explain this calculator code.
goblinko [34]

Answer:

i dont know ask the calc to do it. hehe

Explanation:

7 0
4 years ago
Which statement BEST describes the benefits of muscular fitness training? A. High levels of muscular fitness can improve your se
Alenkasestr [34]
I dont really know too much about this, But i know a decent amount so im going to say C or D
7 0
3 years ago
A network host with an IP address of 192.168.10.200 wants to send a message to a destination computer with an assigned IP addres
Mariulka [41]

Answer:

A Subnet Mask

Explanation:

A Subnet mask is used by the TCP/IP protocol to determine whether a host is on the local Subnet or on a remote network.

In TCP/IP, the parts of the IP address that are used as the network and host addresses are not fixed, so the destination host address 192.168.10.100 cannot be determined by the network host (192.168.10.200) unless it has more information. This information is supplied in another 32-bit number called a Subnet mask.

4 0
4 years ago
While typing out his assignment henry makes use of leading. What could be the probable reason for him to do so.
kiruha [24]

its C because leading is the same thing as line spacing so it basically makes space between each horizontal line


8 0
3 years ago
Read 2 more answers
Other questions:
  • Select the correct answer. Andy wants to become a multimedia producer. Which degree can help him achieve this goal? A. bachelor’
    5·1 answer
  • You could face mandatory revocation of your license as a result of __________ A. lying about ownership of your vehicle. B. drivi
    14·1 answer
  • Can I recover my data from HDD if I just started formatting but did not finish it? (I ceased it!)
    7·1 answer
  • Rapid development programming languages eliminate the possibility of having bugs in code. True or False
    8·1 answer
  • Which of these shortcuts becomes available only when text is highlighted?
    10·1 answer
  • Sam needs to create a spreadsheet for his coworkers. They will need to follow across a long row of data. Sam would like to make
    8·2 answers
  • A systems administrator is designing a directory architecture to support Linux servers using Lightweight Directory Access Protoc
    11·1 answer
  • Let X and Y be two decision problems. Suppose we know that X reduces to Yin polynomial time. Which of the following statements a
    14·1 answer
  • You have learned a lot about the types of careers that are involved with building a playground. Create two job descriptions of p
    7·2 answers
  • What is the difference between * and **operator? in python ​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!