Skip to content

Commit 35a136e

Browse files
Add files via upload
This project checks if a given number is prime. It introduces the concept of loops and conditionals in Python.
1 parent 0ee2da5 commit 35a136e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

PythonBasics_Primenumber.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Kullanıcıdan alının sayı asal mı değil mi, kontrol edelim.
2+
3+
sayi = int(input('Sayı giriniz: '))
4+
5+
if sayi < 2:
6+
print('2 den küçük sayıların asallık kontrolü yapılmaz..!')
7+
else:
8+
is_prime = True
9+
10+
sayac = 2
11+
while sayac < sayi:
12+
if sayi % sayac == 0:
13+
is_prime = False
14+
break
15+
sayac += 1
16+
17+
if is_prime: # is_prime == True
18+
print(f'{sayi} asaldır..!')
19+
else:
20+
print(f'{sayi} asal değildir..!')

0 commit comments

Comments
 (0)