ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 18 - while
    Python 2020. 7. 24. 13:49

    while(조건식)

    조건식의 결과가 참(True)인 동안 반복적으로 실행된는 명령문

     

    ex)

    count = 0
    while count <= 3:
    count += 1 # count = count + 1
    print(" " + str(count)) # 1~4까지 출력됨

     

    입력한 수의 약수 구하기
    약수 : 두 정수 a, b에 대하여 b = ac만족하는 정수 c가 있으면
    a b의 약수라고 하며, 이를 a|b 로 표기한다.

     

    while True:
            num = int(input())
            # b = ac
            i = 1
            while i <= num:
                     if num % i == 0:
                         print("{}".format(i))
                     i += 1
            print("입니다")

            if num == -1:
                break

    'Python' 카테고리의 다른 글

    20 - function  (0) 2020.07.28
    19 - list  (0) 2020.07.27
    17 - print_option  (0) 2020.07.24
    16 - for  (0) 2020.07.22
    15 - if_else  (0) 2020.07.22

    댓글

Designed by Tistory.