這是我的代碼:bookings = ['blue,red', 'green,orange', 'yellow, purple']number = 0b = 0c = 1file_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 + 1results_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')line = file_test.readlines()for item in bookings: line_1 = line[b] line_2 = line[c] answer = input('If first word is then what is the second word') if answer == line_2: print('correct') else: print('wrong') b = b + 2 c = c + 2但是,代碼不會識別答案等于line_2。我無法弄清楚為什么會這樣。我已經(jīng)檢查過這c是正確的數(shù)字,并且line_2與答案相同。但我確實(shí)注意到,當(dāng)我在打印答案時運(yùn)行代碼并且line_2這會返回:redred但我從來沒有在這里添加新的線路功能。任何幫助將不勝感激,因?yàn)槲倚枰獙⒋舜a用于學(xué)校作業(yè)。
添加回答
舉報
0/150
提交
取消
