데이터 구조 및 분석 ch_1_7 Conditon and Loop statement
Jul 3, 2021
»
writing
KAIST 산업및시스템공학과 문일철_ 데이터 구조 및 분석 수업을 참고하여 작성하였습니다
ch_1_7 Conditon and Loop statement
Conditon and Loop statement
1. if : A condition statement - if boolean : statements for True - elif boolean : statements for True - else : statements for False : python does not have a switch-case statement : carefully indentations (들여쓰기)
numScore = 100
if numScore > 90 :
print('A')
numScore = 75
if numScore > 90 :
print('A')
else :
print("Lower grade")
if numScore > 90 :
print('A')
elif numScore > 80 :
print('B')
elif numScore > 70 :
print('C')
else :
print('D or F')
# A
# Lower grade
# C
2. For : A loop statement - for variable in sequence statement for loop - else : a break : continue or break
for itr in range(10):
print(itr)
sum = 0
for itr in range(1,11) :
sum += itr
print(sum)
for itr in range(1,100,10) :
if str == 51:
continue
else :
print(itr)
for itr in range(5):
print(itr)
else :
print('!')
print('done')
for itr in range(5):
if itr == 3:
break
print(itr)
else :
print('!')
print('done')
# 0
# 1
# 2
# 3
# 4
# 5
# 6
# 7
# 8
# 9
# 1
# 3
# 6
# 10
# 15
# 21
# 28
# 36
# 45
# 55
# 1
# 11
# 21
# 31
# 41
# 51
# 61
# 71
# 81
# 91
# 0
# 1
# 2
# 3
# 4
# !
# done
# 0
# 1
# 2
# done