0% found this document useful (0 votes)
11 views

Python

The document provides code snippets to check if a number is prime or not and to print all prime numbers up to a given number. The code uses flags and loops to check for divisibility and output results.

Uploaded by

Devil Pubg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Python

The document provides code snippets to check if a number is prime or not and to print all prime numbers up to a given number. The code uses flags and loops to check for divisibility and output results.

Uploaded by

Devil Pubg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

##### Check number is prime or not

n = int(input("num1 : "))
m = 2
flag = False
while m < n:
if n % m == 0:
flag = True
m += 1
if flag:
print(n, "is not prime")
else:
print(n, "is prime")

**Flag =>>> it acts as a boolean variable indicating a condition to be either true


or false

##### Print prime number

n = int(input("num1 : "))
k = 2
while k <= n:
m = 2
flag = False
while m < k:
if k % m == 0:
flag = True
m += 1
if not flag:
print(k)
k += 1

You might also like