본문 바로가기
Python/Python Examples

[Python Examples] 파이썬 while문 예제: while, if, elif, else

by Henry Cho 2022. 11. 20.
728x90

파이썬 while문 예제: while, if, elif, else

포스트 난이도: HOO_Intern


# Example codes

 

x = 0

print("   x   ","|","    y   ")
print("--------|--------")


while not x > 98: 
    if x >= 0 and x < 1: 
        y = x 
        print("%4.f" % x, "   |", " %4.f " % y)
    elif x >= 1 and x < 2:
        y = x*x 
        print("%4.f" % x, "   |", " %4.f " % y) 
    else:
        y = x+2
        print("%4.f" % x, "   |", " %4.f " % y) 
    x +=1

   x    |     y   
--------|--------
   0    |     0 
   1    |     1 
   2    |     4 
   3    |     5 
   4    |     6 
   5    |     7 
   6    |     8 
   7    |     9 
   8    |    10 
   9    |    11 
  10    |    12 
  11    |    13 
  12    |    14 
  13    |    15 
  14    |    16 
  15    |    17 
  16    |    18 
  17    |    19 
  18    |    20 
  19    |    21 
  20    |    22 
  21    |    23 
  22    |    24 
  23    |    25 
  24    |    26 
  25    |    27 
  26    |    28 
  27    |    29 
  28    |    30 
  29    |    31 
  30    |    32 
  31    |    33 
  32    |    34 
  33    |    35 
  34    |    36 
  35    |    37 
  36    |    38 
  37    |    39 
  38    |    40 
  39    |    41 
  40    |    42 
  41    |    43 
  42    |    44 
  43    |    45 
  44    |    46 
  45    |    47 
  46    |    48 
  47    |    49 
  48    |    50 
  49    |    51 
  50    |    52 
  51    |    53 
  52    |    54 
  53    |    55 
  54    |    56 
  55    |    57 
  56    |    58 
  57    |    59 
  58    |    60 
  59    |    61 
  60    |    62 
  61    |    63 
  62    |    64 
  63    |    65 
  64    |    66 
  65    |    67 
  66    |    68 
  67    |    69 
  68    |    70 
  69    |    71 
  70    |    72 
  71    |    73 
  72    |    74 
  73    |    75 
  74    |    76 
  75    |    77 
  76    |    78 
  77    |    79 
  78    |    80 
  79    |    81 
  80    |    82 
  81    |    83 
  82    |    84 
  83    |    85 
  84    |    86 
  85    |    87 
  86    |    88 
  87    |    89 
  88    |    90 
  89    |    91 
  90    |    92 
  91    |    93 
  92    |    94 
  93    |    95 
  94    |    96 
  95    |    97 
  96    |    98 
  97    |    99 
  98    |   100

 


 

728x90

댓글