Python - Calculate the Square of a number

In this program, you will learn how to calculate the square of the number.


Program Code : 1



    #Example1: Square of the Number
    num = 5
    
    value = num ** 2
    
    print('The square value of {0} number is {1}'.format(num,value))
            
            

Output


    The square value of 5 number is 25
            

In this program, the variable num is squared and stored the result to value variable.
Display value result in the format of string

Program Code : 2



    #Example2: Square of the Float
    num = input('Enter First Number: ')
        
    value = float(num) ** 2
    print('The square value of {0} number is {1}'.format(num, value))
            
            

Output


    Enter First Number: 25
    The square value of 25 number is 625.0
            

In this program, you can enter your desired number in decemal format to square it.

The entered number value is assinged to num variable.
To square the number, you should type cast each number to float data type.

Display num and value values in the format of string.




The following topics can be useful to understand this program.



Related Tutorials