2016-10-02 7 views
0

입력을 받아 특수 문자를 제거하고 모든 대문자를 소문자로 만들고 오프셋이 5 인 아스키 코드로 변환 한 다음 오프셋 된 값을 문자로 다시 변환하여 단어를 형성 할 수 있어야합니다. 나는 점점 형식 오류를 계속 : 'INT'개체가이 result int로 루프를 통해 각 시간을 선언하고 있기 때문에 당신은 TypeError: 'int' object is not iterable at the end을 받고 말ASCII 코드를 텍스트로 변환하는 방법?

string=(str(raw_input("The code is:"))) 

#change it to lower case 
string_lowercase=string.lower() 

print "lower case string is:", string_lowercase 

#strip special characters 

specialcharacters="1234567890~`[email protected]#$%^&*()_-+={[}]|\:;'<,>.?/" 

for char in specialcharacters: 
    string_lowercase=string_lowercase.replace(char,"") 

print "With the specials stripped out the string is:", string_lowercase 

#input offset 

offset=(int(raw_input("enter offset:"))) 

#converstion of text to ASCII code 

for i in string_lowercase: 
    code=ord(i) 
    result=code-offset 

#converstion from ASCII code to text 
for number in result: 
    message=repre(unichr(number)) 
    print message 
+0

result' '는'int'이다 result 이런리스트 위에 루프가 추가 모든 코드되어야한다. 그런 다음 그것을 반복하려고합니다. 대신 당신이 원하는 것은'result.append (code-offset)'입니다. 즉, 실제로'result' 인자를'list'로 초기화해야하므로'result = []'가 루프 앞에 위치해야합니다. – idjaw

답변

0

에서 반복 가능한 없습니다.

#converstion of text to ASCII code 
result = [] 
for i in string_lowercase: 
    code=ord(i) 
    result.append(code-offset) 
관련 문제