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
Need help with this, will give brainliest
Ganezh [65]
What is this? i’m not sure what i’m looking at
7 0
2 years ago
Which object waits for and responds toan event from a GUI component?
irakobra [83]

Answer:

The answer is action eventlistener

Explanation:

It is an event handler and it is easy to implement.In java we call them even listeners it is function or a sub routine or a procedure that waits for an event to occur and respond to an event from a GUI component.

8 0
3 years ago
Most Microsoft Windows fatal errors (blue screen of death) are caused by:
rusak2 [61]

Answer:D) Hardware failure

Explanation: Fatal error are those which stops the function execution of the operating system during the run-time in the Microsoft Windows . These errors. These errors are seen the Microsoft windows due to the major reason of the hardware failure, accessing of the invalid code,operating system files might get corrupted etc. Therefore, the correct option is option(D).

7 0
3 years ago
A company has a file server that shares a folder named Public. The network security policy specifies that the Public folder is a
klasskru [66]

Answer:

authentication

Explanation:

At the authentication process, there is a way of identifying a user, this is typically done by having the user enter a valid user name and valid password before access is granted. Here at authentication the process is based on each user having a unique set of criteria for gaining access.

The AAA server have to ascertain by comparing a user's authentication credentials with other user credentials stored in a database. In the event the credentials match, the user is granted access to the network. But on the other hand, If the credentials varies, and authentication fails then network access will be denied.

3 0
3 years ago
The ________letter of the first word in the Complimentary Closing has a capital letter, everything else is keyed in lower case o
Alona [7]

Answer: enter

\

Explanation:

yes

5 0
3 years ago
Other questions:
  • what is it called when you are biying and selling products via electronic channels such as the internet​
    13·2 answers
  • What is an IP address and where I can find the IP address for my computer?
    14·1 answer
  • Quiz
    6·2 answers
  • 2. Given the following list, write a snippet of code that would print the individual elements of the list using the indexes of t
    13·1 answer
  • Which item is most important for a successful website design?
    6·2 answers
  • When gathering information about certain occupations, be sure to understand how you are paid. What is the difference between a s
    12·2 answers
  • You work for a company that builds custom PCs for select clients. You are training a new employee to evaluate and select appropr
    13·1 answer
  • How do news organizations primarily create revenue?
    12·2 answers
  • Which of the following statements is TRUE of a peer-to-peer network?
    10·1 answer
  • Frrrrrrrrrrreeeeeeeeee brainliest for u
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!