スクランブルされたアルファベットを入力して、AZ アルファベットに変換する必要があります。
これらを整数に変更する必要があると思います。
スクランブルされた入力を取得して整数に変更する方法はありますか?
アップデート:
これまでに書いたコードは次のとおりです。投稿された組み込み関数を使用できません。これは、既に学習したものに違いありません。
ユーザー入力が次の場合:
VNKW KW BO 1WV WJHFJV BJWWXEJ!
目的の出力は次のとおりです。
THIS IS MY 1ST SECRET MESSAGE
import random
def main():
encrypt = [" "] * 26 #all letters available
for numbah in range(26):
letter = chr(numbah+65)
print (letter, end="")
# find position for number
notfound = True
while notfound:
position = random.randint(0, 25)
if encrypt[position] == " ":
notfound = False
encrypt[position] = letter
print("\nScrambled: ", end="")
for numbah in range(26):
print(encrypt[numbah], end="")
print("\n\n ")
msg=input("Please input the scrambled alphabet in order: ")
print("Now input the scrambled message: " + msg)
print("Your unscrambled message reads: ", end="")
for alpha in msg.upper():
if alpha < "A" or alpha > "Z":
print(alpha,end="")
else:
print(encrypt[ ord(alpha) - 65 ], end="")
main()