Python Forum
Storing data/output from a loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Storing data/output from a loop
#6
I have tried using the append function along with some other changes, and it outputs an error.
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.
Reply


Messages In This Thread
Storing data/output from a loop - by Jason613 - Sep-28-2019, 01:24 PM
RE: Storing data/output from a loop - by ichabod801 - Sep-28-2019, 02:15 PM
RE: Storing data/output from a loop - by Jason613 - Sep-28-2019, 04:02 PM
RE: Storing data/output from a loop - by ichabod801 - Sep-28-2019, 05:01 PM
RE: Storing data/output from a loop - by Dora_Deng - Sep-29-2019, 08:01 AM
RE: Storing data/output from a loop - by Jason613 - Sep-29-2019, 02:33 PM
RE: Storing data/output from a loop - by ichabod801 - Sep-29-2019, 02:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I experimented with a loop, and I don't understand how I got my output thinwheats 7 3,002 Mar-18-2020, 07:33 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020