Sep-29-2019, 02:33 PM
I have tried using the append function along with some other changes, and it outputs an error.
1) What does the error means? How could I fix the error?
2) I tried to print the list outside of the loop, and the output is "none". What's wrong with my list?
3) Could you elaborate a bit more about the list and append example on #2?
Thanks for your help.
qxqy=input("Position of Queenie: ").split() qx=int(qxqy[0]) qy=int(qxqy[1]) n=input("Number of puppies: ") n=int(n) list=[] countn=1 for countn in range(1,n+1): countn=str(countn) pxpy_countn=input("Position of Puppy "+countn+": ").split() px_countn=int(pxpy_countn[0]) py_countn=int(pxpy_countn[1]) if abs(px_countn-qx)+abs(py_countn-qy)>10: list=list.append(countn) print("and".join(list))The error is as follow:
Output:Position of Queenie: 2 1
Number of puppies: 4
Position of Puppy 1: 10 1
Position of Puppy 2: 14 -2
Position of Puppy 3: 1 3
Position of Puppy 4: 0 4
Traceback (most recent call last):
File "main.py", line 15, in <module>
print("and".join(list))
TypeError: can only join an iterable
So I have more questions. 1) What does the error means? How could I fix the error?
2) I tried to print the list outside of the loop, and the output is "none". What's wrong with my list?
3) Could you elaborate a bit more about the list and append example on #2?
Thanks for your help.