r/CodingHelp • • Sep 16 '21

[Python] still learning python basics and im stuck with this <function translator at 0x…> error please help

Post image
52 Upvotes

20 comments sorted by

24

u/yes_i_relapsed Sep 16 '21

The last line of your function translator should say return translation

11

u/Eye-Itchy Sep 16 '21

Oh my that was dumb of me thank you

3

u/SensouWar Sep 16 '21

Also, you could save the user input into a new variable, then console log the return value of the function using that input. No need to put everything on a single line, it does not promote code readability. Good luck!

13

u/icjeremy Sep 16 '21

return translator ??

10

u/a1b2c3d4g Sep 16 '21

Someone’s into higher order functions

3

u/Eye-Itchy Sep 16 '21

still learning my basics 😅

4

u/a1b2c3d4g Sep 16 '21

You’re doing great 😊 keep it up!

6

u/Eye-Itchy Sep 16 '21

Got it thank you!

6

u/Tramix42 Sep 16 '21

Looks like you got your answer. Little tip, be consistent on your indentations. You have indents of 1 space only, and indents of 4 spaces. Suggestion, keep all your indents at 4 spaces, it'll look cleaner later on.

1

u/Eye-Itchy Sep 16 '21

thank you, i actually had one more error after that and it was indentation related… lesson learnt👍🏾

2

u/No_Celebration_4991 Sep 16 '21

Keep it going!! I think that’s a great start, hope you are enjoying the process. If you want more challenges you can always go on leetcode/hackerrank great websites to improve your skills.

2

u/Eye-Itchy Sep 16 '21

will do thanks!👍🏾

2

u/[deleted] Sep 16 '21

Ah classic recursion hell :)

s/return translator/return translation

2

u/BrightBulb123 Intermediate Coder Sep 17 '21

Not picking on you, but why does nobody know about screenshots?

2

u/CreedOnNothing Sep 18 '21

Why is it so hard for you people to read lmao

2

u/BrightBulb123 Intermediate Coder Sep 18 '21

It's not that we can't read, it's just an ease of life thing and gives a much clearer picture.

I mean, would you rather have a picture taken on a shaking phone or a clear screenshot?

1

u/CreedOnNothing Sep 18 '21

I get your point, but if we can read he would pick easy for him too (easier to upload from his phone)

2

u/[deleted] Sep 17 '21

It’s working as designed, just maybe not as intended haha. You’re accidentally returning your function instead of what it calculated

Since in Python, functions are “objects”, meaning they can be renamed and passed around like normal data, printing the function itself prints <function name at memory address>. It’s a really handy thing for lots of applications even if confusing when you do it on accident!

1

u/Dasher38 Sep 17 '21

Other comments addressed the functional issue, here is one advice about speed: don't concatenate to a list or string in a loop like that unless the input is small. Every time you do that, python will have to allocate a new one and copy over the old content.

The solution is to append to a list (or use a list comprehension) and then use "".join(the_list) to create the final string in one go. Appending is fine since list over allocates so it will not need to copy the content for every append, only every now and then, which amortizes the reallocation cost.

1

u/[deleted] Sep 22 '21

Your function is just returning a self reference rather than its translation value.