0
条件が真であるかどうかをチェックしようとしています。整数と私は '<'記号を使用していないが、私はまだこのエラーが表示されます。私は本当に混乱しています...'<'文字を使用せずに 'int'と 'str'のインスタンス間で "TypeError: '<"をサポートしない
コード:私が使用
import sys
packets, packets_x, packets_y, packets_z = [], [], [], []
for packet in sys.stdin:
if packet == "\n":
break
packets.append(packet[:-1])
packets_x.append(int(list(packet.split())[0]))
packets_y.append(int(list(packet.split())[1]))
packets_z.append(int(list(packet.split())[2]))
while True:
for number in range(len(packets)):
if int(sorted(packets_x)[0]) == packets_x[number] and int(sorted(packets_y)[0]) == packets_y[number] and int(sorted(packets_z)[0]) == packets_z[number]:
print(packets[number])
packets[number] = "a"
packets_x[number] = "a"
packets_y[number] = "a"
packets_y[number] = "a"
if packets.count("a") == len(packets) + 1:
break
を入力:
6220 1 10 Because he's the hero Gotham deserves,
6210 1 10 Asd
<ENTER>
<ENTER>
- 実際にそれを入力しない、[Enter]をクリックします。 入力を行単位で入力し、一度に入力しないでください。私が手
エラー:
if int(sorted(packets_x)[0]) == packets_x[number] and int(sorted(packets_y)[0]) == packets_y[number] and int(sorted(packets_z)[0]) == packets_z[number]:
TypeError: '<' not supported between instances of 'str' and 'int'
が、これは、Pythonのエラーのいくつかの種類のだろうか?
ヒント:Pythonプロンプトで 'sorted([1、" a string "])'を試して、何が起こるかを見てください。 –
あなたは '<'を使用しませんが、 'sorted()'は使用します。 – Barmar
ああ、大丈夫。ありがとう!私は数字と文字列を一緒に使うことができないことを知らなかった。 – NemPlayer