Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Random Word | Game Word
Beginner Final Project: Hangman

book
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

  1. Set the choose_word_random function using the word_list as an argument.
  2. Return random word from the word_list inside the function using random.choice(...) function.
  3. Test the function using the test_word_list list.

Ratkaisu

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ää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 2
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ä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt