dimanche 29 novembre 2015

word guessing game replacing guesses in python

import random

words = ["stack", "queue", "tree", "linked list", "software", "hardware", "operating systems",
"algorithm", "computer", "network"]

PLAYER_NAME=raw_input("What is your name? ")
print("Hey, "),PLAYER_NAME
print("You will guess this words.."),words

def random_choice(words):
    randomword=random.choice(words)
    return randomword
random_choice(words)

# Your second function is responsible of initializing the word with '' (dashes).
# The initialize word has to be a word that is represented with a list.
# Example: Word that will be guessed = COMPUTER


def initalizing_word(words):
    initalized_word=[]
    randomword=random_choice(words)
    for i in range(1,len(randomword)+1):
        initalized_word.append('-')
    print(initalized_word),"is the word that you will be guess."
    print(randomword)
    return initalized_word
randomword=random.choice(words)
initalizing_word(words)

# Your third and last function is responsible of replacing the correct letters to its
# corresponding indexes in the list and word.

def replace_word(randomword,initalized_word):
    while True:
        guess=raw_input("your guess pls..\n")
        if len(guess)>len(randomword) or len(guess)<1:
            print("This is impossible.")
        if len(guess)>1:
            print("You must enter just one string.")
        if len(guess)==1 and guess!=int: #having problem at this part. i can't replace correct guesses to the initilazed_word list.
            if guess in randomword:
                initilazed_word.replace("-",guess)
        print(initilazed_word)
initilazed_word=initalizing_word(words)
replace_word(randomword,initilazed_word)

Hey there! I am trying to code word guessing game.. However, i can't find a solution for replacing True guesses to the initilazed _word list. Furthermore i'm thinking that i overused function calls, so there is two different words to guess like

['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',     '-', '-'] is the word that you will be guess.
operating systems

['-', '-', '-', '-', '-', '-', '-'] is the word that you will be guess.
network

i guess im using funtions wrong :| i need your help for these problems..

furthermore.. i expect an output if the randomword is stack and guess s

['s', '-', '-', '-', '-'] and on..




Aucun commentaire:

Enregistrer un commentaire