#### I have two variables that I know are equal but my if statement does not recognise this?

``````bookings = ['blue,red', 'green,orange', 'yellow, purple']
number = 0
b = 0
c = 1

file_test = open('test_1.txt' , 'wt')

results_song = []

for item in bookings:
words = bookings[number].split(',')
results_song.append(words[0])
results_song.append(words[1])

number = number + 1

results_song_str = '\n'.join(results_song)
print(results_song_str)

file_test.write(results_song_str)

file_test.close()

file_test = open('test_1.txt' , 'r')

for item in bookings:

line_1 = line[b]
line_2 = line[c]
answer = input('If first word is then what is the second word')

print('correct')
else:
print('wrong')

b = b + 2
c = c + 2
``````

``````red

red
``````

1 个回复

``````# ...

for item in bookings:
line_1 = line[b]
line_2 = line[c]

# ...
``````

``````Your Answer: 'red'
``````

``````# ...

for _ in range(len(bookings)):   # I took the freedom to modify the loop conditions

line_1 = line[b].replace('\n','')
line_2 = line[c].replace('\n','')

# ...
``````

``````# ...

with open('test_1.txt' , 'r') as file_test:

for _ in range(len(bookings)):
line_1 = line[b]
line_2 = line[c]

# ...
``````

1 为什么我的语句询问两个变量是否相等不起作用？

2 while 循环无法识别 if 语句和变量？

4 两个相等的变量不会触发 if() 语句

7 除非有cout语句，为什么我的代码不起作用？

2017-12-04 08:41:46 0 90   c++/ cout
8 我必须让我的大部分变量最终成功吗？