|
2 | 2 | # Points assigned to each letter of the alphabet
|
3 | 3 | POINTS = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]
|
4 | 4 | score1 = score2 = 0
|
| 5 | +# Gives a random letter to the user to start with |
5 | 6 | print("Enter a word starting with the letter "+ chr(r.randint(65, 90)))
|
6 | 7 | # Get input words from both players
|
7 | 8 | word1 = input("Player 1:")
|
8 | 9 | word2 = input("Player 2:")
|
9 | 10 |
|
10 | 11 | # Calculating the score of Player1
|
| 12 | +# Points given to each letter are irrespective of the case |
11 | 13 | for i in word1:
|
12 | 14 | if word1.isupper():
|
13 | | - score1 += POINTS[ord(i) - ord('A')] |
| 15 | + score1 += POINTS[ord(i) - ord('A')]#ord returns the ASCII value of the letter |
14 | 16 | elif word1.islower():
|
15 | 17 | score1 += POINTS[ord(i) - ord('a')]
|
16 | 18 | #Claculating the score of Player2
|
17 | 19 | for i in word2:
|
18 | 20 | if word2.isupper():
|
19 | | - score2 += POINTS[ord(i) - ord('A')] |
| 21 | + score2 += POINTS[ord(i) - ord('A')]#ord returns the ASCII value of the letter |
20 | 22 | elif word2.islower():
|
21 | 23 | score2 += POINTS[ord(i) - ord('a')]
|
22 | 24 |
|
|
0 commit comments