20 AnswersNew Answer
20 AnswersNew Answer
You're gonna have to do your homework alone.
def my_func(start, end): return [i**2 for i in range(start, end)] print(my_func(1, 31))
Or you wont. *sigh*
Correct and thank you
Thank you its for learning purposes as well, and I'm learning from you guys..thanks
Honfu you guess right
Thanks team sololearn
Okay, elvisreal, now we see a bit what has been the problem with this thread to begin with, although nobody cared back then. You came with a question that read like 'write that code for me'. And instead of telling you that you should try it yourself, they all just dished out the solution to you. And now see what has happened: Three full months later, you still don't even know that you have to print out a return value if you want to see it! There's nothing bad about being at whatever point you are, because everybody was there once. But do you want to stay there forever? And to the other people: Do you want this person to remain a beginner for all eternity? Coding can only be learned by writing code with your own hands! So write your codes yourself! And make other people write their codes themselves!
Honfu thanks for your opinion, but coding cant only be learned that way, because people are different and they learn differently..Its just like teaching a child how to ride a bike, sooner or latter the child starts to ride its own bike.. i know I'm a beginner, for a month and half I had to leave programing, to get something very important to me. But I'm back now and NO i will never stay a beginner for eternity.
You are right Honfu... we should guide, not do the writing.
Are you suggesting i should use list comprehension, im yet to understand how it works
Gonçalo Magalhaes Run your code, it was showing "No output"
If You are doing this for learning purpose rhen it ohk but if it is for homework.... you are going wrong. x= for i in range(1,31): x. append(i**2) print(x)
A more pythonic function, using list comprehension: def my_func(start, stop): return [i**2 for i in range(start, stop)] I added a small perk, that allows you to do what you want, but also to specify other start and stop values ;) For your objective: my_func(1, 31) Happy coding!
Let me guess - you didn't print out the result?
def sq(): print([j**2 for j in range(1,31)]) sq()
SoloLearn Inc.4 Embarcadero Center, Suite 1455
Send us a message