Task 10 Linear Function Answer

Back to General discussions forum

momojoyy     2024-03-26 05:28:09

I'm struggling with this problem. I'm able to get the correct answer but its being rejected because of formatting. How do i get rid of the commas between the x and y pair so that the expected answer and my answer match?

for example: Expected Answer = (1 0) My answer = (1,0)

My code below:

n=int(input())
ary1=[]

for i in range(n):
   k=[int(n) for n in input().split()]
   x1=k[0]
   y1=k[1]
   x2=k[2]
   y2=k[3]
   a=int((y1-y2)/(x1-x2))
   b=int(y1-a*x1)
   ary1.append((a, b))

print(*ary1, sep=" ")

Expected Answer :
(28 -788) (-54 368) (-41 -805) (-8 833) (37 -147) (74 -51) (-14 -919) (39 -746) (-95 -604) (5 -575) (99 -704) (40 -314) (42 66) (-41 -606) (30 -256)

My Answer : (28, -788) (-54, 368) (-41, -805) (-8, 833) (37, -147) (74, -51) (-14, -919) (39, -746) (-95, -604) (5, -575) (99, -704) (40, -314) (42, 66) (-41, -606) (30, -256)

momojoyy     2024-03-26 05:40:40

I believe i figured it out. Fixing the last two lines resolved it. Cheers. n=int(input()) ary1=[]

for i in range(n):
   k=[int(n) for n in input().split()]
   x1=k[0]
   y1=k[1]
   x2=k[2]
   y2=k[3]
   a=int((y1-y2)/(x1-x2))
   b=int(y1-a*x1)
   ary1.append((a,b))
   ary2=str(ary1)[1:-1]
print(*ary2.replace(",",''), sep='')
Please login and solve 5 problems to be able to post at forum