0
Pls, how can I write this same code, with def function and still get d same result? I've been trying but different result.
4 Answers
0
because you use "return number" inside of the for loop. pop it out to the outter most level of the function and it will go through the entire loop and then print the whole list
note: when you return inside of a function, that function is then complete and it moves on to the next line of code
+ 1
Wow!!! Thanks alot. I've gotten it.
0
Try it out inside that code! Let's see where the issue is, just give it a shot and even if it breaks the code, save it so we all can see why
0
def number():
number=[]
n=int(input("Enter a num"))
for i in range(0,n):
num=int(input("Type a num:-"))
x=number.append(num)
return number
print(number())
#This is d one I tried it's only printing the 1st number I type, then it breaks. Unlike d 1st one that will print the full list.