简体   繁体   English

+ 不支持的操作数类型:'int' 和 'function'

[英]unsupported operand type(s) for +: 'int' and 'function'

Ok so I need to encrypt or decrypt a message given a list of integers, a message, and a keystream value.好的,所以我需要加密或解密给定整数列表、消息和密钥流值的消息。 Whenever I run my function I get this error:每当我运行我的函数时,我都会收到此错误:

File "C:\Users\v\Desktop\Assignment 1\cipher_functions.py", line 152, in <module>
result += decrypt_letter(i, get_next_keystream_value)
File "C:\Users\v\Desktop\Assignment 1\cipher_functions.py", line 51, in <module>
key_stream = (ord_char - key_value) builtins.TypeError: unsupported operand type(s) for -: 'int' and 'function'

These are the 2 functions which I believe are involved:这些是我认为涉及的两个功能:

def encrypt_letter(my_char, key_value):
    '''(str, int) -> str
    '''
    my_list = ['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']
    ord_char = (ord(my_char.upper()) - 65)
    key_stream = (ord_char + key_value)

    if key_stream > 25:
        result = (key_stream - 26)
    elif key_stream <= 25:
        result = key_stream

    key_streamed_value = my_list[result]

    return key_streamed_value

def decrypt_letter(my_upper_char, key_value):
    '''(str, int) -> str
    '''
    my_list = ['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']    
    ord_char = (ord(my_upper_char) - 65)
    key_stream = (ord_char - key_value)

    if key_stream < 0:
        result = (key_stream + 26)
    elif key_stream >= 0:
        result = key_stream

    key_streamed_value = my_list[result]

    return key_streamed_value


def process_message(deck_cards, my_message, convert):
    '''(list of int, str, str) -> str
    '''
    result = ""
    new_message = clean_message(my_message)
    for i in new_message:
        if convert == 'e':
            result += encrypt_letter(i, get_next_keystream_value)
        elif convert == "d":
            result += decrypt_letter(i, get_next_keystream_value)
        return result

Does anyone know why this problem is occurring?有谁知道为什么会出现这个问题?

It looks like the problem is that get_next_keystream_value is not defined anywhere.看起来问题是get_next_keystream_value没有在任何地方定义。

It is unclear if it is meant to be a variable which you have not initialized, or if it should be a function call for a function that has not been coded yet, in which case it should be get_next_keystream_value() .目前尚不清楚它是否意味着您尚未初始化的变量,或者它是否应该是尚未编码的函数的函数调用,在这种情况下它应该是get_next_keystream_value() Given the structure of your code, it looks like you are trying to pass it as the key_value , in which case you need to initialize it to an integer first.鉴于您的代码结构,您似乎试图将其作为key_value ,在这种情况下,您需要key_value其初始化为整数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 **或pow()不支持的操作数类型:“函数”和“整数” - unsupported operand type(s) for ** or pow(): 'function' and 'int' TypeError:*:&#39;function&#39;和&#39;int&#39;不支持的操作数类型 - TypeError: unsupported operand type(s) for *: 'function' and 'int' + 不支持的操作数类型:“int”和“function”k - unsupported operand type(s) for +: 'int' and 'function' k python *: 'int' 和 'function 不支持的操作数类型 - python unsupported operand type(s) for *: 'int' and 'function “不支持 ** 或 pow() 的操作数类型:&#39;function&#39; 和 &#39;int&#39;” - "unsupported operand type(s) for ** or pow() : ' function' and 'int' " 类型错误:不支持 + 的操作数类型:&#39;function&#39; 和 &#39;int&#39; - TypeError: unsupported operand type(s) for +: 'function' and 'int' +不支持的操作数类型:“函数”和“整数”错误 - Unsupported operand type(s) for +: 'function' and 'int' error 如何修复类型错误:+ 的不支持的操作数类型:'function' 和 'int'? - How to fix the Type error: unsupported operand type(s) for +: 'function' and 'int'? function 中的 Function 返回“TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'” - Function in function returning “TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' ” 类型错误:+ 不支持的操作数类型:&#39;function&#39; 和 &#39;int&#39;...需要支持 - TypeError: unsupported operand type(s) for +: 'function' and 'int'...Need support
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM