165k views
2 votes
Use do while loop to find square root of odd number 1 to 200​

User Rabejens
by
7.0k points

1 Answer

1 vote
Here's an example of using a do-while loop in Python to find the square root of odd numbers from 1 to 200:

```
import math

i = 1

# loop through odd numbers from 1 to 200
while i <= 200:
# check if number is odd
if i % 2 != 0:
# find square root using math.sqrt() function
sqrt_i = math.sqrt(i)
print("The square root of", i, "is", sqrt_i)
i += 1
```

This code uses a while loop to iterate through the odd numbers from 1 to 200. It checks if each number is odd using the modulus operator `%`. If the number is odd, it calculates the square root using the `math.sqrt()` function and prints the result. The loop then continues to the next odd number until it reaches 200.
User Mark Vincze
by
7.5k points

No related questions found