커뮤니티

고용노동부, 산업인력공단과 함께하는 강원도 유일한 기업중심 IT전문교육기관 ICT융합캠퍼스만의 특별한교육입니다.
공인 IT숙련기술인의 다양한 접근방법으로 전문가다운 실무교육을 받을 수 있습니다.

Category

교육강좌

언어 Python & Ruby - 조건문

페이지 정보

작성자 관리자 댓글 0건 조회 2,516회 작성일 20-06-10 13:54

본문

조건문

기본문법

Python

1
2
3
4
if True:
print("code1")
print("code2")
print("code3")

Ruby

1
2
3
4
5
if true
puts("code1")
puts("code2")
end
puts("code3")

실행결과

1
2
3
code1
code2
code3

Python | Ruby

조건문의 활용

Python

1
2
3
4
input = 11
real = 11
if real == input:
print("Hello!")

Ruby

1
2
3
4
5
input = 11
real = 11
if real == input
puts("Hello!")
end

실행결과

1
Hello!

Python | Ruby

else

Python

1
2
3
4
5
6
input = 11
real = 11
if real == input:
print("Hello!")
else:
print("Who are you?")

Ruby

1
2
3
4
5
6
7
input = 11
real = 11
if real == input
puts("Hello!")
else
puts("Who are you?")
end

실행결과

1
Hello!

Python | Ruby

else if

Python

1
2
3
4
5
6
7
8
9
input = 33
real_egoing = 11
real_k8805 = "ab"
if real_egoing == input:
print("Hello!, egoing")
elif real_k8805 == input:
print("Hello!, k8805")
else:
print("Who are you?")

Ruby

1
2
3
4
5
6
7
8
9
10
input = 33
real_egoing = 11
real_k8805 = "ab"
if real_egoing == input
puts("Hello!, egoing")
elsif real_k8805 == input
puts("Hello!, k8805")
else
puts("Who are you?")
end

실행결과

1
Who are you?

Python | Ruby

  • 트위터로 보내기
  • 페이스북으로 보내기
  • 구글플러스로 보내기

답변목록

등록된 답변이 없습니다.