Sunday, January 2, 2022

How to print the Prime Numbers between 1 to 100 using Python Program

A Python Program to print the Prime Numbers between 1 to 100 using For Loop
import sys
print("Python Version: ", sys.version)

n = 100
j = 0
k = 0
primelist = [ ]

for i in range(1, n + 1):
    for j in range(1, i + 1):
        if i % j == 0:
            k = k + 1
    if k == 2:
        primelist.append(i)
        k = 0
    else:
        k = 0
print('The Prime Numbers between {0} and {1} are: '.format(1, n), primelist)

# ------------------------------------------------------------------------------------------------------------------------ #
Output:
C:\Users\tpreddy\PycharmProjects\pythonProject\PyLab1\venv\Scripts\python.exe C:/Users/tpreddy/PycharmProjects/pythonProject/PyLab1/Temp1.py
Python Version:  3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]
The Prime Numbers between 1 and 100 are:  [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

Process finished with exit code 0
# ------------------------------------------------------------------------------------------------------------------------ #

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog