제로베이스 데이터 취업스쿨_파이썬 기초 이론 #3

이혜지·2023년 3월 8일
0

**다자택일 조건식 (if~ elif~)사용시 주의할점: 조건식 순서가 중요함
exampleScore =int(input("성적 입력: "))
grades= ' '

if exampleScore >=70: #90점도 C학점임.. 범위를 명확하게 줘서 해결가능--> 70<= exampleScore <80
grades='C'
print('성적:{} \t 학점:{}'.format(exampleScore, grades))

**input()함수
exampleScore =int(input("성적 입력: "))
grades= ' '

if 70<= exampleScore <80:
grades='C'

print('성적:{} \t 학점:{}'.format(exampleScore, grades))

**반복문
#1. 횟수에 의한 반복: 주로 for문 사용
#2. 조건에 의한 반복: 주로 while문 사용

for i in range(1,10):
print('{} {} ={}'.format(2,i,(2i)))

**range()함수
for i in range(1,11,2):
print(i)

**조건에 의한 반복: while문
endNum=5 #1.초기식
n=0

while n<= endNum: #2.조건식
print(n)
n+=1 #3. 증감식

**반복문 제어: continue
for i in range(100):
if i%7 !=0: #7의 배수가 아니라면
continue #다시 for문으로 올라간다

print("{}는 7의 배수입니다.".format(i))

**반복문 제어: break
num=0
while True:
print("Hello")
num+=1
if num >=5:
break

print("The END")

*중첩반복문: 반복문 안에 또다른 반복문을 선언
for i in range(1,10):
for j in range(i):
print('
', end='') #end='' --> 개행하지 않음
print() #개행

*구구단 출력
for i in range(1,10):
for j in range(2,10):
print('{}
{} = {}\t'.format(j,i, j*i), end='') #end='' --> 개행하지 않음
print() #개행

profile
문과생IT / BA박사과정중 / 창업 또는 기획자희망

0개의 댓글