日々考えたり

プログラミング学習記録、読んだ本の感想など

MAMP:Pythonで素数を表示

勉強記録です。

 

題材

1~50までの値で、素数のみを表示

 

Code

#!C:/MAMP/bin/python/bin/python
print 'Content-type: text/html'
print ''

 

#1~50の素数のみを表示
i = 1
while i <= 50:
    j= 1
    while j < i:
        if (i%j == 0) and (j != 1):
            break
        else:
            j = j+1
    if j == i:
        print i
    i=i+1