+ 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
20 odpowiedzi
+ 4
You're gonna have to do your homework alone.
+ 4
def my_func(start, end):
return [i**2 for i in range(start, end)]
print(my_func(1, 31))
+ 2
Or you wont. *sigh*
+ 2
:)
+ 2
Correct and thank you
+ 2
All...
+ 2
Thank you its for learning purposes as well, and I'm learning from you guys..thanks
+ 2
Gonçalo Magalhaes Run your code, it was showing "No output"
+ 2
Honfu you guess right
+ 2
Thanks team sololearn
+ 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!
+ 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.
+ 1
You are right Honfu... we should guide, not do the writing.
+ 1
Are you suggesting i should use list comprehension, im yet to understand how it works
+ 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.
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)
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!
0
Let me guess - you didn't print out the result?
0
def sq():
print([j**2 for j in range(1,31)])
sq()
0
Yap