상세 컨텐츠

본문 제목

#9. 백준 11654번 (python)

공부/파이썬

by 김지똥 2024. 3. 1. 17:36

본문

https://www.acmicpc.net/problem/11654

 

11654번: 아스키 코드

알파벳 소문자, 대문자, 숫자 0-9중 하나가 주어졌을 때, 주어진 글자의 아스키 코드값을 출력하는 프로그램을 작성하시오.

www.acmicpc.net

 

 

change = input()

if type(change) == str:
    print(ord(change))
else type(change) == int:
    print(chr(change))

첨에 else를 사용했더니 오류가 나네요

 

change = input()

if type(change) == str:
    print(ord(change))
elif type(change) == int:
    print(chr(change))

이렇게 했더니 맞기는 한데

 

출력은 안 됩니다

 

왜죠?

 

 

ord() ===> 문자를 아스키코드로!!

chr() ===> 아스키코드를 문자로!!

출처: https://knowallworld.tistory.com/19 [뭐든지 다 알아보자:티스토리]

 

[백준 파이썬 11654번]아스키 코드 ★ord(),chr()함수 이해★VER2.0

ord() ===> 문자를 아스키코드로!! chr() ===> 아스키코드를 문자로!! ex> ord('a') ==> 97 chr(97) == > a. VERSION 2.0 import sys A = (sys.stdin.readline().rstrip()) print(ord(A)) #ord() , chr() , hex() ORD() 꼭 기억하자!!!

knowallworld.tistory.com

 

 

이거라네요

 

그렇다면

 

흠..

 

print(ord(input()))

 

다른 블로그 보면 이런 답이 나오는데

 

저는 이해가 잘..

 

경우를 나눠서 해야하는 거 아닌가

 

숫자일 때랑 문자일 때로 .. 아닌가...

 

잘 모르겠네요 ㅎㅎ

 

내가 맞나?/

 

답변 부탁드려요

'공부 > 파이썬' 카테고리의 다른 글

#11. 백준 11718번 (python)  (0) 2024.08.10
#10. 백준 5622번 (python)  (0) 2024.08.07
#8. 백준 9086번 (python)  (0) 2024.03.01
#7. 백준 2743번 (python)  (1) 2024.03.01
#6. 백준 27866 (python)  (1) 2024.03.01

관련글 더보기