2016-10-02 9 views
0

入力を受け取り、特殊文字を削除し、すべての大文字を小文字にし、オフセットが5のASCIIコードに変換し、オフセット値を文字に戻して単語にする必要があります。 「int型のオブジェクトは、あなたがintとしてループ上resultを毎回宣言しているので、あなたが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.append(code-offset)'だと思います。つまり、実際に 'result'引数を' list'として初期化する必要があるので、 'result = []'はループの前に置かなければなりません。 – idjaw

答えて

0

反復可能ではありません:私は例外TypeErrorを得続けます。 resultはリストであり、ループの上にループの上に追加されるすべてのコードでなければなりません。

#converstion of text to ASCII code 
result = [] 
for i in string_lowercase: 
    code=ord(i) 
    result.append(code-offset) 
関連する問題