108k views
3 votes
Assume there are two variables, k and m, each already assigned a positive integer value and further assume that k's value is smaller than m's. Write the code necessary to compute the number of pertect squares between k and m. (A perfect square is an integer like 9, 16, 25, 36 that is equal to the square ot another integer (in this case 393, 4*4, 5*5, 6*6 respectively). Assign the number you compute to the variable q. For example, if k and m nad the values 10 and 40 respectively, you would assign 3 to q because between 10 and 40 there are these perfect squares: 16, 25, and 36.

User Honmaple
by
4.6k points

1 Answer

6 votes

Answer:

Lets us take k, m = 10, 40

q = 0

i = k

while i <= m:

if int(i*0.5)*2 == i:

q += 1

i += 1

User Rasmi Ranjan Nayak
by
3.9k points