Home / Programs / Write a program to print square root of every alternate number in the range 1 to 10
🚀 Programming Example

Write a program to print square root of every alternate number in the range 1 to 10

👁 731 Views
💻 Practical Program
📘 Step Learning

Write a program to print square root of every alternate number in the range 1 to 10

📌 Information & Algorithm

Here is a Python program to print the square root of every alternate number in the range 1 to 10:

💻 Program Code

import math

for num in range(1, 11, 2):
    sqrt = math.sqrt(num)
    print("The square root of", num, "is", sqrt)

                        

🖥 Program Output

The square root of 1 is 1.0
The square root of 3 is 1.7320508075688772
The square root of 5 is 2.23606797749979
The square root of 7 is 2.6457513110645907
The square root of 9 is 3.0

                            

📘 Explanation

In this program, we first import the math module, which provides various mathematical functions, including the square root function. We then use a for loop with a step size of 2 to iterate over every alternate number in the range 1 to 10 (i.e., 1, 3, 5, 7, 9). For each number in the range, we calculate its square root using the math.sqrt() function, and then we print out the result using the print() function.

This program demonstrates the sequential flow of execution in Python, where the statements are executed in the order in which they appear in the code. The for loop causes the statements inside the loop (i.e., the calculation of the square root and the printing of the result) to be executed repeatedly for every alternate number in the specified range.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.