我如何使用 cnt =+1 解决 python 分配问题

how do i solve python allocation problem with cnt =+1

我是 python 的新手,正在尝试按后代顺序对分数进行排序,看看谁的分数相同。这是代码

Score = [90, 80, 92, 88, 75, 88, 80, 80, 90, 90, 90, 75]
Score.sort(reverse=True)
sorted_unique_score = []

#sorting in desc order
for score in Score:
  if score not in sorted_unique_score:
    sorted_unique_score.append(score) 

#find the same scores
for unique_score in sorted_unique_score:
  cnt = 0
  for score in Score:
    if unique_score == score:
      cnt = cnt + 1 # somehow this one doesn't work -->  cnt =+ cnt 1
    else:
      continue

  if cnt == 1:
    print(f"for {unique_score}: is a unique score")  
  else:
    print(f"for {unique_score} : {cnt} students got the same score")

这非常有效,但我想知道为什么下面的这个不起作用。

Score = [90, 80, 92, 88, 75, 88, 80, 80, 90, 90, 90, 75]
Score.sort(reverse=True)
sorted_unique_score = []

#sorting in desc order
for score in Score:
  if score not in sorted_unique_score:
    sorted_unique_score.append(score) 

#find the same scores
for unique_score in sorted_unique_score:
  cnt = 0
  for score in Score:
    if unique_score == score:
      cnt =+ cnt 1 
    else:
      continue

  if cnt == 1:
    print(f"for {unique_score}: is a unique score")  
  else:
    print(f"for {unique_score} : {cnt} students got the same score")

唯一不同的是cnt =+ cnt +1部分

你应该这样写:cnt += cnt 1 而不是:cnt =+ cnt 1