Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的函数不起作用,它说';继续';不正确地在循环中_Python - Fatal编程技术网

Python 我的函数不起作用,它说';继续';不正确地在循环中

Python 我的函数不起作用,它说';继续';不正确地在循环中,python,Python,你的代码搞乱了。看起来您刚刚开始编程 导入字符串 def换档(偏移): 新消息=“” 字母表=字符串。ascii_小写 对于邮件中的信函: letter=letter.lower()#还不能处理大写字母 如果字母.isalpha(): 移位位置=(字母表索引(字母)+偏移量)%len(字母表) 新位置=字母表[移位位置] 新消息+=新位置 #这些将不会改变 如果字母中的“”或“/t”或“/n”: 新信息+=信函 elif letter.isnumeric(): 新信息+=信函 其他: 打印(“记

你的代码搞乱了。看起来您刚刚开始编程

导入字符串
def换档(偏移):
新消息=“”
字母表=字符串。ascii_小写
对于邮件中的信函:
letter=letter.lower()#还不能处理大写字母
如果字母.isalpha():
移位位置=(字母表索引(字母)+偏移量)%len(字母表)
新位置=字母表[移位位置]
新消息+=新位置
#这些将不会改变
如果字母中的“”或“/t”或“/n”:
新信息+=信函
elif letter.isnumeric():
新信息+=信函
其他:
打印(“记录消息时出错。请检查输入。\n”)
返回新消息
尽管如此:
inp=int(输入(“”)
1=生成代码
2=解码消息
3=退出
输入您的选择:''))
偏移量=3
如果inp==1:
message=input(“要加密的输入消息:\n”)
新消息=移位(偏移)
打印(新消息)
elif inp==2:
偏移量=-3
message=input(“要解密的输入消息:\n”)
新消息=解密=移位(偏移量)
打印(新消息)
elif inp==3:
打破

我认为您应该阅读此

您应该从正确设置问题的格式开始。看起来
continue
不在循环中。您希望它在代码结束时做什么?
continue
应该是哪个循环的一部分?您发布的代码缩进不正确,因此很难判断。您的缩进似乎到处都是。缩进在Python中不仅仅是一种风格。它会影响代码的工作方式。在您的例子中,所发布的代码以一个
continue
语句结束,没有缩进。这意味着它在文件的顶层。这毫无意义。没有它可以应用于的循环。因此出现了错误。删除它,或将其移动到循环体中。提供
#This is hard for me to handle; I need some one's help!


alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

    inp = int(input('''1 = Make a code
    2 = Decode a message
    3 = Quit
    Enter your selection: '''))
    if inp == 1:
      def shift(offset):

    message = input("Input Message You Would Like Encrypted:\n")
    new_message = ''

    for letter in message:

        letter = letter.lower() #doesn't handle upper-case yet

        if letter.isalpha():
            shift_pos = alphabet.index(letter) + offset
            new_pos = alphabet[shift_pos]
            new_message += new_pos

        #these will not be shifted

        elif ' ' or '/t' or '/n' in letter: 
            new_message += letter

        elif letter.isnumeric(): 
            new_message += letter

        else:
            print("An error took place in recording the message. Check input.\n")

    print(new_message)


shift(-1)
if inp == 2:
  def shift(offset):

    message = input("Input Message You Would Like Encrypted:\n")
    new_message = ''

    for letter in message:

        letter = letter.lower() #doesn't handle upper-case yet

        if letter.isalpha():
            shift_pos = alphabet.index(letter) + offset
            new_pos = alphabet[shift_pos]
            new_message += new_pos

        #these will not be shifted

        elif ' ' or '/t' or '/n' in letter: 
            new_message += letter

        elif letter.isnumeric(): 
            new_message += letter

        else:
            print("An error took place in recording the message. Check input.\n")

    print(new_message)


shift(+1)
continue