+ 6

Question on Python3

Pls, help me out Write a Python function to create and print a list where the values are square of numbers between 1 and 30

16th Aug 2019, 9:32 PM
elvisreal
elvisreal - avatar
22 Respostas
+ 4
You're gonna have to do your homework alone.
16th Aug 2019, 9:37 PM
HonFu
HonFu - avatar
+ 4
def my_func(start, end): return [i**2 for i in range(start, end)] print(my_func(1, 31))
29th Nov 2019, 11:49 PM
elvisreal
elvisreal - avatar
+ 2
Or you wont. *sigh*
16th Aug 2019, 9:38 PM
HonFu
HonFu - avatar
+ 2
:)
16th Aug 2019, 10:22 PM
elvisreal
elvisreal - avatar
+ 2
Correct and thank you
16th Aug 2019, 10:23 PM
elvisreal
elvisreal - avatar
+ 2
All...
16th Aug 2019, 10:27 PM
elvisreal
elvisreal - avatar
+ 2
Thank you its for learning purposes as well, and I'm learning from you guys..thanks
17th Aug 2019, 11:01 AM
elvisreal
elvisreal - avatar
+ 2
GonƧalo Magalhaes Run your code, it was showing "No output"
29th Nov 2019, 11:39 PM
elvisreal
elvisreal - avatar
+ 2
Honfu you guess right
29th Nov 2019, 11:49 PM
elvisreal
elvisreal - avatar
+ 2
Thanks team sololearn
29th Nov 2019, 11:50 PM
elvisreal
elvisreal - avatar
+ 2
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!
29th Nov 2019, 11:56 PM
HonFu
HonFu - avatar
+ 2
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.
30th Nov 2019, 12:15 AM
elvisreal
elvisreal - avatar
+ 1
You are right Honfu... we should guide, not do the writing.
16th Aug 2019, 9:45 PM
Steven M
Steven M - avatar
+ 1
Are you suggesting i should use list comprehension, im yet to understand how it works
29th Nov 2019, 11:33 PM
elvisreal
elvisreal - avatar
+ 1
def my_func(start, end): return [i**2 for i in range(start, end)] print(my_func(1, 31)) this is a python answer.
25th Sep 2021, 7:03 PM
Shubham Bhatia
Shubham Bhatia - avatar
0
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)
17th Aug 2019, 8:54 AM
Sarvesh Yadav
Sarvesh Yadav - avatar
0
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!
29th Nov 2019, 11:23 PM
GonƧalo Magalhaes
GonƧalo Magalhaes - avatar
0
Let me guess - you didn't print out the result?
29th Nov 2019, 11:43 PM
HonFu
HonFu - avatar
0
def sq(): print([j**2 for j in range(1,31)]) sq()
26th Feb 2020, 5:15 PM
Rupesh Sai Manikanta
Rupesh Sai Manikanta - avatar
0
Yap
21st Feb 2024, 12:49 PM
Dawit Mengesha Beriso
Dawit Mengesha Beriso - avatar