yekang

홀수/짝수판별 및 윤년 확인 및 논리연산자 및 소수 판별 본문

빅데이터/파이썬

홀수/짝수판별 및 윤년 확인 및 논리연산자 및 소수 판별

예캉 2017. 6. 30. 09:56

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
for i in range(10):
    if (i+1)%2==0:
        print('%d is even'%(i+1))
    if (i+1)%2==1:
        print('%d is odd'%(i+1))
 
print()
#위의 코드 개선/짝수냐 홀수냐 두번 물어보기(1번 질문하기. a냐 b냐)
for i in range(10):
    if (i+1)%2==0:
        print('%d is even'%(i+1))
    else:
        print('%d is odd'%(i+1))
 
'''
'''
조건을 2개이상 다룰 때 사용하는 연산자 
and 연산자 두 개를 볼때 두 개 다 true인경우
or 연산자 둘 중 하나 이상 true인경우
'''
'''
#윤년 확인법
year = 2400
if (year%4==0 and year%100!=0)or(year%400==0):
    print('leap year')
else:
    print('general year')
    '''
cs




1
2
3
4
5
6
7
8
9
10
11
12
#1000~2000 사이의 소수(prime number)를 판별하여 출력하시오
for j in range(2,12):
    number = j
    count =0
    for i in range(number):
        if number%(i+1)==0:
            count=count+1
    
    if (count==2):
        print('소수 %d'%number)
    #else:
     #   print('합성수 count= %d'%count)
cs


Comments