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>