def times(num):
i = 1
ll = []
while i < 10:
result = num * i
ll = [result.append()] #problem
i = i + 1
return ll
Hi, everyone. If you enter a number of num in the function times(num), it would be nice if the number multiplied by 1 to 9 was included in the list.
Run the code above
It says 'int' object has no attribute 'append'.
In this case, how can I put the int in the list ll?
Thank you.
For your information, Jump to Python provided the following code.
def gugu(n):
result = []
i = 1
while i < 10:
result.append(n*i)
i = i + 1
return result
You must invoke the append()
method in the list ll
.
append()
adds the call factor to the end of the list.
def times(num):
i = 1
ll = []
while i < 10:
result = num * i
ll.append(result) #problem
i = i + 1
return ll
© 2024 OneMinuteCode. All rights reserved.