forked from prathimacode-hub/Awesome_Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScrabble.py
36 lines (29 loc) · 1.11 KB
/
Scrabble.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import random as r
# Points assigned to each letter of the alphabet
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]
score1 = score2 = 0
# Gives a random letter to the user to start with
print("Enter a word starting with the letter "+ chr(r.randint(65, 90)))
# Get input words from both players
word1 = input("Player 1:")
word2 = input("Player 2:")
# Calculating the score of Player1
# Points given to each letter are irrespective of the case
for i in word1:
if word1.isupper():
score1 += POINTS[ord(i) - ord('A')] #ord returns the ASCII value of the letter
elif word1.islower():
score1 += POINTS[ord(i) - ord('a')]
#Claculating the score of Player2
for i in word2:
if word2.isupper():
score2 += POINTS[ord(i) - ord('A')] #ord returns the ASCII value of the letter
elif word2.islower():
score2 += POINTS[ord(i) - ord('a')]
#Prints the winner
if score1 > score2:
print("Player 1 wins!")
elif score1 < score2 :
print("Player 2 wins!\n")
elif score1 == score2:
print("Tie!\n")