-2

I try to execute this source code for the multiplication but it doesn't work, it's shows error on te return , I want to know if it's possible why that happen, and how I can change my code so that it will work. thanks you

def multiples():
      return [lambda x : i * x for i in range(4)]

print (m[2] for m in multiples())
Tharif
  • 13,538
  • 9
  • 54
  • 76
  • 1
    @Amadan that's for the French language, not programming questions in French. – dimo414 Jul 14 '15 at 03:59
  • @dimo414: Gaah you're right. There's a portuguese SO, then didn't pay attention and... yeah :P – Amadan Jul 14 '15 at 04:01
  • 1
    @YounessKhater I'm afraid StackOverflow is an [English-language forum](http://meta.stackexchange.com/questions/13676/do-posts-have-to-be-in-english-on-stack-exchange). There may [one day](https://blog.stackexchange.com/2014/02/cant-we-all-be-reasonable-and-speak-english/) be a French StackOverflow, but for now you'll need to post your question in English. – dimo414 Jul 14 '15 at 04:03
  • Uh, I'm guessing at parts of the French but, "Hello world, I wrote this code to multiply, but it doesn't work. Do y'all have any ideas? And how should I modify this so it'll work, thanks for your responses in advance." – NightShadeQueen Jul 14 '15 at 04:08
  • I was in the middle of writing an answer when this got locked, so ill just post it here since its different from the duplicate post. Il ne marche pas parce que `i` est 3 après la liste fait. Puis, quand tu exécute `print [m(2) for m in multipls()]`, il multiplie 2 avec 3 chaque fois. Tu peux faire: `def multipls(): for i in range(4): yield lambda x:i*x` Je suis désolé pour ma mauvaise français. – Vaibhav Aggarwal Jul 14 '15 at 04:08
  • thank you all guys , I'll edit my question in english so that you can understand it , thanks Vaibhav Aggrwal – Youness Khater Jul 14 '15 at 12:12

1 Answers1

3

I think its probably due to the missing indentations. Always use proper indentations in python.

In your print statement the brackets are misplaced.

Try using this print (m[2] for m in multipls())

Try to ask questions in 'English' so that everyone can understand and give you answers. If you ask in English most of us could help you.

Tony Roczz
  • 2,328
  • 5
  • 31
  • 55