Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1.     elif choice == "a5":
  2.         print("Provide me with a string in the following form: 'a2b4A5s3B1'. Where letters represent players and numbers score.")
  3.         print("Lower case letters means the player is given more points and upper case letters means the following points are subtracted from the players total.")
  4.         fullstring = input("Give me the string: ")
  5.         players = []
  6.         score = []
  7.         scoreindex = 0
  8.         output = ""
  9.         for character in fullstring:
  10.             if character.isalpha():
  11.                 if character.lower() not in players:
  12.                     players.append(character.lower())
  13.                     if character.islower():
  14.                         score.append(fullstring[fullstring.index(character) + 1])
  15.                     else:
  16.                         score.append(0 - int(fullstring[fullstring.index(character) + 1]))
  17.                 else:
  18.                     scoreindex = players.index(character.lower())
  19.                     if character.islower():
  20.                         score[scoreindex] = int(score[scoreindex]) + int(fullstring[fullstring.index(character) + 1])
  21.                     else:
  22.                         score[scoreindex] = int(score[scoreindex]) - int(fullstring[fullstring.index(character) + 1])
  23.         for i in range(len(players)):
  24.             if output == "":
  25.                 output += players[i] + " " + str(score[i])
  26.             else:
  27.                 output += ", " + players[i] + " " + str(score[i])
  28.         print("\nMarvin says:\n")
  29.         print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement