-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram2.py
43 lines (30 loc) · 901 Bytes
/
Program2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Write a function in python which accept a number from user to return True, if the number
# is a prime number else return False. Use this function to print all prime numbers from 1
# to 100.
# Prime Number counter
prime_number = 0
# Function to check if a number is prime
def is_primenumber(x):
if x >= 2:
for y in range(2, x):
if not (x % y):
return False
else:
return False
return True
# Taking input of a number from the user to check if the number is prime
if_prime = int(
input(
"Enter a number to check: "
)
)
print(is_primenumber(if_prime))
# Execution of the function for multiple numbers
for i in range(
int(
input("How many number to check:") + 1
)):
if is_primenumber(i):
prime_number += 1
print(i)
print("We found" + str(prime_number) + "prime numbers.")