# Weekly Challenge #2 – Basic Word Game – Solutions

Note: This contains answers to the Basic Word Game challenge. Have a go at the challenge before coming here!

### Bronze

```word = input("Please enter your word: ")

word_length = len(word)
score = 0

if word_length == 3:
score = 1
elif word_length == 4 or word_length == 5:
score = 2
elif word_length == 6 or word_length == 7:
score = 3
elif word_length == 8 or word_length == 9:
score = 5

```Console.Write("Please enter your word: ");

int score = 0;

if (word.Length == 3)
{
score = 1;
}
else if (word.Length == 4 || word.Length == 5)
{
score = 2;
}
else if (word.Length == 6 || word.Length == 7)
{
score = 3;
}
else if (word.Length == 8 || word.Length == 9)
{
score = 5;
}

(Python only) – I have chosen to store the length of the word inside a variable called word_length in order to make the code more readable. You may skip this step and access the length each time by using len(word).

### Silver

```word = input("Please enter your word: ")

word_length = len(word)
score = 0

while word_length < 3 or word_length > 9:
word = input("Invalid word, please re-enter: ")
word_length = len(word)

if word_length == 3:
score = 1
elif word_length <= 5:
score = 2
elif word_length <= 7:
score = 3
else:
score = 5

```
```string word;
do
{
} while (word.Length < 3 || word.Length > 9);

int score = 0;

if (word.Length == 3)
{
score = 1;
}
else if (word.Length <= 5)
{
score = 2;
}
else if (word.Length <= 7)
{
score = 3;
}
else
{
score = 5;
}

Notice that I have now simplified the If/Elif statement since I have validation to ensure that all words are between 3-9 characters long.

### Gold

```word = input("Please enter your word: ").upper()

word_length = len(word)
score = 0

while word_length < 3 or word_length > 9:
word = input("Invalid word, please re-enter: ").upper()
word_length = len(word)

if word_length == 3:
score = 1
elif word_length <= 5:
score = 2
elif word_length <= 7:
score = 3
else:
score = 5

consonant_count = 0
vowel_count = 0
for char in word:
if char in "AEIOU":
vowel_count += 1
else:
consonant_count += 1

if consonant_count >= 4:
score += 2
if vowel_count == 1:
score += 2

```string word;
do
{
} while (word.Length < 3 || word.Length > 9);

int score = 0;
if (word.Length == 3)
{
score = 1;
}
else if (word.Length <= 5)
{
score = 2;
}
else if (word.Length <= 7)
{
score = 3;
}
else
{
score = 5;
}

int consonant_count = 0, vowel_count = 0;

foreach (char c in word)
{
if ("AEIOU".Contains(c))
{
vowel_count++;
}
else
{
consonant_count++;
}
}
if (consonant_count >= 4)
{
score += 2;
}
if (vowel_count == 1)
{
score += 2;
}