Random Word
To play the game it is needed to choose one gameword
randomly from the word_list
. To do that we create choose_word_random
function.
Tehtävä
Swipe to start coding
- Set the
choose_word_random
function using theword_list
as an argument. - Return random word from the
word_list
inside the function usingrandom.choice(...)
function. - Test the function using the
test_word_list
list.
Ratkaisu
99
1
2
3
4
5
6
7
8
9
10
import random
# Set the choose_word_random function
def choose_word_random(word_list):
# Return the random word from the word_list
return random.choice(word_list)
# Test the function
test_word_list = ['sun', 'sky', 'water', 'fire', 'nature']
print(choose_word_random(test_word_list))
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 1. Luku 2
99
1
2
3
4
5
6
7
8
9
10
import random
# Set the choose_word_random function
___:
# Return the random word from the word_list
___ ___.choice(___)
# Test the function
test_word_list = ['sun', 'sky', 'water', 'fire', 'nature']
print(___(test_word_list))
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme