0
我已經創建了一個代碼(應該)能夠將字符串轉換爲ascii'代碼'。但是,它不會輸出我想要的內容。下面是有關的代碼:爲什麼我的'祕密消息/破譯'代碼不起作用?
if Code_Decode=='C':
print("What is your 'Shift number'?")
SNum=int(input("> "))
print("What is your message?")
msg=input("> ")
code=[ord(c) for c in msg]
new_code=[x+(SNum) for x in code]
print(','.join(str(x) for x in code))
else:
print("What is your 'Shift number'?")
SNum=int(input("> "))
print("Type in your ASCII values, separated by a comma")
a = [int(x) for x in input().split(",")]
ans=[x-(SNum) for x in a]
ans2=[chr(i) for i in ans]
print(' '.join(str(x) for x in ans2))
用戶應該輸入一個「移位號」,那麼字符串,並且它應該是轉換成ASCII碼,在移位數添加到每個單獨的值。 但是,當我運行代碼時,不會添加移位號碼。忽略if和else行。
例子:(這是當我運行的代碼會發生什麼)
Do you want to Create(C) a message, or Decode(D) a message? (C/D)> C
What is your 'Shift number'?
> 2
What is your message?
> Hello World
72,101,108,108,111,32,87,111,114,108,100
Again? Y/N > Y
Do you want to Create(C) a message, or Decode(D) a message? (C/D)> D
What is your 'Shift number'?
> 2
Type in your ASCII values, separated by a comma
72,101,108,108,111,32,87,111,114,108,100
F c j j m U m p j b
正如你所看到的,方案產出與一些混亂的向上字母。我如何解決它?
對不起格式不好,我是新手。 – AJ123