如何在python行尾添加字符串

用条件将file.txt行尾的字符串连接起来

我有2个输入和一个file.txt

file.txt有以下几行

A1|books
A2|pen
A3|ball

输入1,输入2

  • input1必须选择必须添加的行(A1,A2或A3)
  • input2必须选择要添加的字符串

输入1 = A1,输入2 = |笔|

那么我期望的file.txt是

A1|books|pen|
A2|pen
A3|ball