Ads

Breaking

Friday, February 21, 2020


How to Write a Program to print first 50 even numbers square using while loop in python

How to Write a Program to print first 50 even numbers square using while loop in python


1. First we have to taking input from user
2. Using while loop for checking the condition that the given number are even or not.
Code:
n=int(input("enter the number  "))       # taking variable n as input
i=1         #taking variable i and initialize it to 1
while i<= n+1:        # taking as range i.e., i is greater and equal to the given digit
        i+=1
        if i%2==0:        # checking condition that i is even or divided by two or not
                print(i**2,end=" ")         #printing i to the power of two
Output:
enter the number 50
4 16 36 64 100 144 196 256 324 400 484 576 676 784 900 1024 1156 1296 1444 1600 1764 1936 2116 2304 2500 2704

No comments:

Post a Comment