A game displays a picture and the user is asked to spell the matching word by entering letters - Scottish Highers Computing Science - Question 8 - 2022
Question 8
A game displays a picture and the user is asked to spell the matching word by entering letters.
When a correct letter is entered by the user the letter is filled in... show full transcript
Worked Solution & Example Answer:A game displays a picture and the user is asked to spell the matching word by entering letters - Scottish Highers Computing Science - Question 8 - 2022
Step 1
Process 1
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The first process of the game involves displaying a picture and prompting the user to guess the word that corresponds to that picture by entering letters.
Step 2
Process 2
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The second process involves checking whether the entered letters are correct and filling the corresponding boxes with the correct letters, while also displaying the number of letters the user has correctly guessed.
Step 3
Using a design technique of your choice, design a program to read in this file, pick one of the words at random and assign it to a variable called chosenWord.
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To implement this:
Open the file 'threeLetters.txt' for reading.
Store the words in a suitable data structure, such as a list.
Generate a random number within the range of the list length to select a word at random.
Assign the randomly selected word to the variable called chosenWord.
Step 4
i) assign the variable hintOne the first letter of the word stored in the chosenWord.
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
hintOne = chosenWord[0]
Step 5
ii) assign the variable hintTwo a random letter from the word stored in the chosenWord variable.
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
// Assuming a language like Python
import random
randomIndex = random.randint(0, len(chosenWord) - 1)
hintTwo = chosenWord[randomIndex]
Step 6
Using a programming language of your choice, write the code to implement this feature.
97%
121 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
numLetters = 0
usedLetters = []
letter = input('Enter a letter: ')
while letter in usedLetters:
print('Letter already used. Please try again.')
letter = input('Enter a letter: ')
usedLetters.append(letter)
numLetters += 1
Join the Scottish Highers students using SimpleStudy...