我想知道如何輸入一個字符串並從字典中獲取多個密鑰?例如,這是我的代碼,我想打印「歡迎來到黑社會」,並用我的字典中的字母進行編碼。字典中的多個鍵?
def main():
print("*********************************************************************************************")
print("What exactly is your use for this? Whatever, Enter a message because your hiding something...")
print("*********************************************************************************************")
userInput = input("Enter your message to encode: ")
userInput = userInput.lower()
# encoding dictionary
encoding = {"a":"b","b":"c","c":"d","d":"e","e":"f","f":"g","g":"h","h":"i","i":"j","j":"k","k":"l","l":"m","m":"n",
"n":"o","o":"p","p":"q","q":"r","r":"s","s":"t","t":"u","u":"v","v":"w","w":"x","x":"y",
"y":"z","z":"a"," ":"-"}
#userInput = encoding[key]
for key in encoding:
if (userInput == key):
print(encoding[key])
break
main()
爲了您的編碼做類似'CHR(ORD(「一」)+ 1)',而不是寫出來的字典 –