Источник Ссылка
pikey
  • 121
  • 2
  • 9

Я тут, с вашей помощью, допилил то, что нужно было допилить. В принципе, всё работает, как тебуется. Единственное, что хотелось бы прояснить для себя - как добиться того же результата, но с более компактным кодом?

Например, вот одна функция:

def newScores():
    global result
    global scores
    result = int(input("Enter 1, if the computer won, or enter '0' otherwise: "))
    if (result==1):
        print ("PC's won this round, total score list has been adjusted:")
        scores[0] = (scores[0]+1)
        scores[3] = (scores[3]+1)
    else:
        print ("You've won this round, total score list has been adjusted:")
        scores[1] = (scores[1]+1)
        scores[2] = (scores[2]+1)
    print (scores)
newScores()
  • как написать операции по изменению значений строк в списке поболеелучшей?

И вот:

def updateScores():
    global scores
    scores = [str(x) for x in scores]
    print ("")
    # the next 2 lines is there for testing, should be removed later on
    print ("The 'scorelist' has been converted to strings:")
    print (scores)
    scores[0] = (scores[0]+" "+scores[1]+"\n")
    scores[1] = (scores[2]+" "+scores[3])
    scores.remove(scores[2])
    scores.remove(scores[2])
    print (scores)
    f = open("scoretest.txt", "w+")
    line = f.writelines(scores)
    f.close()
updateScores()

Как все эти операции со строками написать в более сжатом виде?