grue
grue

Reputation: 13

TypeError 'int' not callable but I'm passing a string to my decrypt function in python

I'm working on a function that is passed a encrypted string, then returns the decoded string. The error message is TypeError: 'int' object is not callable. How do I tell python the argument is a string? ...or what am I telling python to make it think I'm passing an 'int'?

Thanks!

this is from pythonchallenge.com[1]

the decrpytion is each letter is written as 2 letters previous.

'ams' = 'you'

def decrypt(msg):
    ord = 0
    decoded = ""
    for letter in msg:
        #any number from 97 to 121 will have no rem. They don't warp around.
        #121 & 122 will have rem 1 & 2, so they need +=97 
        ord = (ord(letter) + 2)%123
        if ord < 97:
            ord += 97
        decoded += ord
    return decoded

Upvotes: 0

Views: 86

Answers (3)

hilberts_drinking_problem
hilberts_drinking_problem

Reputation: 11602

You define ord = 0 locally in line 2, overriding function ord. Consider a different name.

Upvotes: 2

Zizouz212
Zizouz212

Reputation: 4998

def decrypt(msg):
    ord = 0

The red light is going off. ord is the name of a python function. You would never want to use the name of a function as a variable name. You lose access to that function, and can't use it later on. Rename it to value or something. Call 1('hello there!') is not going to work: How can I make 1 a function?

Upvotes: 4

Adam Hughes
Adam Hughes

Reputation: 16309

The problem is:

ord(letter)

ord is an integer so you can't do ord(letter)

Upvotes: 0

Related Questions