Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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_Loops - Fatal编程技术网

Python 如何运行循环直到得到每个字母

Python 如何运行循环直到得到每个字母,python,loops,Python,Loops,我正在编写我的凯撒密码程序,当我试图加密我的消息时遇到了一个问题。错误为“函数不可编辑”。所以基本上我想运行for循环,直到它遍历字符串中的所有字母 def message(): message = input("Enter your message here: ").upper() return message def key(): while True: key = int(input("Enter your shift or key betw

我正在编写我的凯撒密码程序,当我试图加密我的消息时遇到了一个问题。错误为“函数不可编辑”。所以基本上我想运行for循环,直到它遍历字符串中的所有字母

def message():
        message = input("Enter your message here: ").upper()
    return message
def key():
    while True:
        key = int(input("Enter your shift or key between the numbers of 1-26: "))
        if key >=1 and key<=26:
            return key

def encrypt(message, key):
    output = []
    for symb in message:
        numbers = ord(symb) + 90 - key
        output.append(numbers)
    print(output)
def消息():
message=input(“在此处输入您的消息:”).upper()
回信
def key():
尽管如此:
key=int(输入(“在1-26之间输入移位或键:”)

如果键>=1且键不重用名称。将
加密
消息
密钥
参数重命名为其他参数

def encrypt(m, k):
    ...

def main():
    encrypt(message(), key())

不要重复使用名字。将
加密
消息
密钥
参数重命名为其他参数

def encrypt(m, k):
    ...

def main():
    encrypt(message(), key())

您有与函数同名的变量,这会在运行时导致冲突

弄清楚谁是谁

def message():
    msg = input("Enter your message here: ").upper()
    return msg

def key():
    while True:
        k = int(input("Enter your shift or key between the numbers of 1-26: "))
        if k >=1 and k <=26:
           return k
def消息():
msg=input(“在此处输入消息:”).upper()
返回消息
def key():
尽管如此:
k=int(输入(“在数字1-26之间输入shift或key:”)

如果k>=1且k则变量与函数同名,这会在函数运行时导致冲突

弄清楚谁是谁

def message():
    msg = input("Enter your message here: ").upper()
    return msg

def key():
    while True:
        k = int(input("Enter your shift or key between the numbers of 1-26: "))
        if k >=1 and k <=26:
           return k
def消息():
msg=input(“在此处输入消息:”).upper()
返回消息
def key():
尽管如此:
k=int(输入(“在数字1-26之间输入shift或key:”)

如果k>=1和k,您必须调用您的函数。很抱歉,我不太明白。请您详细说明。变量和函数都称为
消息
,这导致了这一冲突。您感谢Python中使用的提示
key>=1和key您必须调用您的函数。很抱歉,我不太明白。请详细说明。变量和函数都被称为
message
,这导致了这一冲突。您感谢Python中使用的提示
key>=1和key