파이썬 '%'이거 어떻게 써야 할까요?

kdm1362의 이미지

다른 글들이 다들 어려워 보여서 부끄럽지만
검색할 때 %가 무시되서 검색이 안되어 여러분들께 여쭈어 봅니다.
%가 말썽을 부리는데 도와주세요.

일단 제가 짜 본 코드는 두 수의 최대공약수를 구하는 것입니다

a, b = raw_input().split(' ')
int(a);int(b);
 
def Euclid(one, two):
    if one<two:
        one, two=(two, one)
    while True:
        if one==two:
            return one
        if two==0:
            return one
 
        one, two = two, one%two    //오류발생!!
 
print Euclid(a, b)

%를 나머지 구하는데 쓰려고 했는데 오류 코드를 보니
문자열 처리를 하려고 하다 정수자료를 만나 오류를
내는 것 같이 나옵니다.

Traceback (most recent call last):

File "C:/hello.py", line 12, in
print Euclid(a, b)
File "C:/hello.py", line 10, in Euclid
one, two = two, one%two

TypeError: not all arguments converted during string formatting

조언 부탁 드립니다.

peecky의 이미지

one과 two가 int 타입이 아니라 str 타입인데 % 연산을 써서 나는 오류입니다.

print type(one)
print type(two)
해보시면 type 'str' 이라고 뜰 겁니다.

kdm1362의 이미지

정말 str형 자료가 되어있네요!
캐스트 연산의 사용법을 몰라서 생긴 일이었군요

댓글 감사합니다.