Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6f12a3c

Browse files
Merge pull request #571 from NancyNegi23/main
Add Scrabble
2 parents 722f9ac + 346bad3 commit 6f12a3c

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
23.6 KB
Loading[フレーム]

‎BasicPythonScripts/Scrabble/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Scrabble
2+
3+
## Description
4+
5+
- It is a fun game to know your word strength.The more difficult and random words you more are the chances of your win.
6+
- It has pre-defined scores for each letter. In accordance with this score board total score of the player is calculated and winner is announced.
7+
- It has random method imported.
8+
9+
## Setup instructions
10+
11+
You just need to have latest installation of Python and you are good to go!
12+
13+
## Detailed explanation
14+
15+
__Pre-defined scores:[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]__.
16+
Every number in the list is corresponding to the no of pionts for each letter of the alphabet.
17+
The letters which are common are least scored and the one which occurs in few words are of more value.
18+
Punctuation marks are of value - 0. Every letter is given a score according to the score chart, then adding up the values of each letter final score is calculated.
19+
20+
21+
22+
## Output
23+
24+
![ExampleOutput](/Scrabble/images/Outputimage.png)
25+
## Author(s)
26+
27+
[Nancy Negi](https://github.com/NancyNegi23)

‎BasicPythonScripts/Scrabble/Scrabble.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import random as r
2+
# Points assigned to each letter of the alphabet
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+
score1 = score2 = 0
5+
# Gives a random letter to the user to start with
6+
print("Enter a word starting with the letter "+ chr(r.randint(65, 90)))
7+
# Get input words from both players
8+
word1 = input("Player 1:")
9+
word2 = input("Player 2:")
10+
11+
# Calculating the score of Player1
12+
# Points given to each letter are irrespective of the case
13+
for i in word1:
14+
if word1.isupper():
15+
score1 += POINTS[ord(i) - ord('A')] #ord returns the ASCII value of the letter
16+
elif word1.islower():
17+
score1 += POINTS[ord(i) - ord('a')]
18+
#Claculating the score of Player2
19+
for i in word2:
20+
if word2.isupper():
21+
score2 += POINTS[ord(i) - ord('A')] #ord returns the ASCII value of the letter
22+
elif word2.islower():
23+
score2 += POINTS[ord(i) - ord('a')]
24+
25+
#Prints the winner
26+
if score1 > score2:
27+
print("Player 1 wins!")
28+
elif score1 < score2 :
29+
print("Player 2 wins!\n")
30+
elif score1 == score2:
31+
print("Tie!\n")
32+
33+
34+
35+
36+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is a very simple amd beginner friendly project.
2+
3+
All you need is the Python (3.X) installed in your device and then you are good to go.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /