gpt4 book ai didi

python - <> 语法错误

转载 作者:太空宇宙 更新时间:2023-11-03 17:06:38 26 4
gpt4 key购买 nike

我正在尝试完成这项作业:

这就是我所拥有的,但我遇到了语法错误>

粘贴代码:

# Specify where the input and output file is

InputFile = open('C:\Python\unsorted_fruits.txt', 'r')
OutputFile = open('C:\Python\sorted_fruits.txt', 'w')

# Read the input file

Fruits = InputFile.readlines()

# Sort the items in the list
Fruits.sort()

# Remove the blank lines and write the file
for fruit in Fruits:
if fruit <>"\n": # if fruit is blank, skip the write
OutputFile.write(fruit) # otherwise write the fruit to the output file


# Close the input and output file
InputFile.close()
OutputFile.close()

最佳答案

只需将“<>”替换为“!=”,因为“<>”在python3中已弃用,可以用作“!=”。

关于python - <> 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34521750/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com