Это говорит о синтаксической ошибке в моем коде, вот новый кусок, который я недавно добавил, который должен иметь ошибку где-то. Я новичок в python, любая помощь очень ценится. Возможно, что-то с отступом, но я не могу видеть, где и она не определяет линию :(Сообщение об ошибке синтаксиса, на python idle
def store_results(class_number, name, score):
class_number = str(class_number) + ".txt" #this adds '.txt' to the end of the file (therefore creating a text file) so it can be used to create a file under the name of the class
file = open(class_number, 'a') #opens the file in 'append' mode so you don't delete all the information
#file.write(str(students_names))
file.write(str(name + " : ")) #writes the name and ":" to file
file.write(str(score)) #writes the score to file
file.write('\n')#writes the score to the file
file.close()#safely closes the file to save the information
def store_results(class_number, name, score):
class_file = "{}.txt".format(class_number) # this adds '.txt' to the end of the file (therefore creating a text file) so it can be used to create a file under the name of the class
with open(class_file, 'a') as f: # opens the file in 'append' mode so you don't delete all the information
f.write("{}: {}\n".format(name, score)
def store_results(class_number, name, score): # this adds '.json' to the end of the file (therefore creating a json file)
class_file = "{}.json".format(class_number) # first step: load the existing data
if not os.path.exists(class_file):
scores = {}
else:
with open(class_file, 'r') as f:
scores = json.load(f)
scores.setdefault(name, []).append(score)
with open(class_file, 'w') as f:
json.dump(scores, f)
сообщение об ошибке просто говорит:
**SYNTAX ERROR: INVALID SYNTAX**
Однако курсор перескакивает назад к этой линии
def store_results(class_number, name, score):
Всегда публиковать полное сообщение об ошибке. Сделайте это как можно проще для нас, чтобы помочь вам, и вы получите точные ответы быстрее. – timgeb
Хорошо, спасибо, я отредактировал его с ошибкой –
добавить полное сообщение об ошибке (с номером строки и т. Д.) – furas