커뮤니티

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

Category

교육강좌

언어 Python & Ruby - 논리 연산

페이지 정보

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

본문

논리 연산

논리 연산자란?

OR

OR 진리표

True or True True
True or False True
False or True True
False or False False

Python

1
2
3
4
5
6
7
in_str = input("아이디를 입력해주세요.\n")
real_egoing = "egoing"
real_k8805 = "k8805"
if real_egoing == in_str or real_k8805 == in_str:
print("Hello!")
else:
print("Who are you?")

Ruby

1
2
3
4
5
6
7
8
9
puts("아이디를 입력해주세요")
input = gets.chomp()
real_egoing = "egoing"
real_k8805 = "k8805"
if real_egoing == input or real_k8805 == input
puts("Hello!")
else
puts("Who are you?")
end

AND

 AND 진리표

True and True True
True and False False
False and True False
False and False False

Python

if를 중첩해서 사용한 예제

1
2
3
4
5
6
7
8
9
10
11
input_id = input("아이디를 입력해주세요.\n")
input_pwd = input("비밀번호를 입력해주세요.\n")
real_id = "egoing"
real_pwd = "11"
if real_id == input_id:
if real_pwd == input_pwd:
print("Hello!")
else:
print("잘못된 비밀번호입니다")
else:
print("잘못된 아이디입니다")

 and로 통합한 예제

1
2
3
4
5
6
7
8
input_id = input("아이디를 입력해주세요.\n")
input_pwd = input("비밀번호를 입력해주세요.\n")
real_id = "egoing"
real_pwd = "11"
if real_id == input_id and real_pwd == input_pwd:
print("Hello!")
else:
print("로그인에 실패했습니다")

 Ruby

if를 중첩해서 사용한 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
puts("아이디를 입력해주세요")
input_id = gets.chomp()
puts("비밀번호를 입력해주세요")
input_pwd = gets.chomp()
real_id = "egoing"
real_pwd = "11"
if real_id == input_id
if real_pwd == input_pwd
puts("Hello!")
else
puts("잘못된 비밀번호입니다")
end
else
puts("잘못된 아이디입니다")
end

 and로 통합한 예제 

1
2
3
4
5
6
7
8
9
10
11
puts("아이디를 입력해주세요")
input_id = gets.chomp()
puts("비밀번호를 입력해주세요")
input_pwd = gets.chomp()
real_id = "egoing"
real_pwd = "11"
if real_id == input_id and real_pwd == input_pwd
puts("Hello!")
else
puts("로그인에 실패했습니다")
end

NOT

Not은 영상 수업이 없습니다.

 Not 진리표

not True False
not False True

참고

github

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

답변목록

등록된 답변이 없습니다.