Answer to Question #87305 in Python for Alex McMullen

Question #87305
Assume there is a variable, h already associated with a positive integer value. Write the code necessary to count the number of perfect squares whose value is less than h, starting with 1. (A perfect square is an integer like 9, 16, 25, 36 that is equal to the square of another integer (in this case 3*3, 4*4, 5*5, 6*6 respectively).) Assign the sum you compute to a variable q For example, if h is 19, you would assign 4 to q because there are perfect squares (starting with 1) that are less than h are: 1, 4, 9, 16.
1
Expert's answer
2019-04-01T08:35:43-0400
h = int(input('Enter value h:'))
i = 1
q = 0
sq = 0
while (i*i) < h:
    sq = (i*i)
    q += 1
    i += 1
print("Count the number of perfect squares whose value is less than {} is: {}".format(h, q))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS