Я работал на простой Цезарь сдвиг в питона, но когда я пытаюсь запустить его он говорит, что:прилагая ул на ул
File "Ceaser Shift.py", line 36, in main
ciphertext += shift(letter,shift)
TypeError: 'str' object is not callable
Я пытался выяснить, почему он делает это, и я могу добавить строку в нормальную среду IDLE и не видел ничего интерактивного, потому что я не переопределял str нигде в моем скрипте. Любая помощь будет замечательной!
Мой код:
## Doesn't support changing shifts during computation, to do this either the database must be re-written or script restarted
import time, os, string
global selmemo
shiftmemo = {}
def shift(l,shift):
if l not in shiftmemo:
charset = list(string.ascii_lowercase)
place = charset.index(l.lower())
shiftplace = charset.index(shift.lower())
shiftmemo[l] = charset[(place+shiftplace)%25]
return shiftmemo[l]
def main():
shift = None
ciphertext = ""
print("--- Welcome ---")
print("--- Ceaser Shifter ---")
print("Commands: shift, encrypt, clear, print, quit")
choice = input(": ")
while choice != "quit":
if choice == "shift":
shift = input("Please enter a shift letter: ")
elif choice == "encrypt" and shift != None:
uparse = input("Enter your plaintext: ")
for letter in uparse:
if letter.lower() in string.ascii_lowercase:
ciphertext += shift(letter,shift)
else:
ciphertext += letter
elif choice == "clear":
shift = ""
ciphertext = ""
shiftmemo = {}
elif choice == "print":
print(ciphertext)
else:
pass
choice = input(": ")
main()
Ждать, никогда. Большое спасибо за наблюдение! Недостаток сна подходит ко мне, я полагаю – Clement