所以我的家庭作業(yè)是編寫一個(gè)執(zhí)行 ROTn 編碼的程序。意思是將一串字母按值 n 移動(dòng)。例如: if n = 2, then"a"將"c"在編碼時(shí)。我們應(yīng)該將移位后的字符串存儲(chǔ)在一個(gè)變量中。所以我剛剛開始這個(gè)講座,所以我們還沒有學(xué)到很多關(guān)于python的東西。這個(gè)問題應(yīng)該是可以解決的,不需要導(dǎo)入東西。所以我的想法是單獨(dú)移動(dòng)每個(gè)字母,然后將其存儲(chǔ)為一個(gè)數(shù)組。然后我可以將它作為字符串輸出print(''.join(my_array)。但是對于自動(dòng)校正系統(tǒng),移位的字符串應(yīng)該存儲(chǔ)在一個(gè)變量中,這給我?guī)砹藛栴}。我不知道怎么做。if __name__ == "__main__": plain_text = "abc" shift_by = 1# perform a ROTn encodingplain_text = input("Please enter a password: ")shift_by = int(input("Enter a value to shift the password: "))store_shift = []x = 0for n in plain_text: if n.isalpha(): n = chr(ord(n) + shift_by) store_shift.append(n) x += 1encoded = ... #here should be the shifted stringprint(''.join(store_shift)請忽略我的錯(cuò)誤變量名。隨意糾正文體錯(cuò)誤等??偨Y(jié)一下; 我無法將變量中的字母數(shù)組作為字符串存儲(chǔ)。例如; array["a", "b", "c"]應(yīng)該存儲(chǔ)在variable = abc(作為字符串)
如何將變量中的字母列表存儲(chǔ)為字符串
動(dòng)漫人物
2022-06-14 16:20:17