mardi 6 octobre 2015

Why doesn't this stop shuffling after 12 shuffles?

So, I want python to shuffle values from a list 12 times (as shown below). But when it reaches the 12th shuffle, it continues infinitely.

        for i in range(12):
            entry.delete(0, tkinter.END)
            random.shuffle(words)
            label.config(text=str(words[1]))
            scoreLabel.config(text="Time: " + str(score)+ "s")

Also, I've tried this but nothing happens

        if wordcount == '12':
            scoreLabel.config(text="You did it in: " + str(score))
            label.config(text="FINISHED")

If it helps, this is what the wordcount is linked to:

wordcount = 0

def nextWord():
        global wordcount

        entry.focus_set()

        if entry.get().lower() == words[1].lower():
            wordcount += 1
            wordcounter.config(text="Words: " + str(wordcount))

This part is above where the problem is because if I swap it around, it won't do anything when it is run. Thanks.

I've also tried:

words = ["Games","Development","Keyboard","Speed","Typer","Anything","Alpha","Zealous","Accurate","Basics","Shortcut","Purpose","Window","Counter","Fortress","Modification","Computer","Science","History","Football","Basketball","Solid","Phantom","Battlefield","Advanced","Warfare","Download","Upload","Antidisestablishmentarianism","Supercalifragilisticexpialidocious","Discomobobulation","Liberated","Assassin","Brotherhood","Revelation","Unity","Syndicate","Victory"]
wordlist = len(words)


    entry.delete(0, tkinter.END)

    for i in range(12, wordlist):
#Tried with and without [i] below where using [i] throws the 
TypeError: 'str' object does not support item assignment error

            random.shuffle(words[i])
            label.config(text=str(words[1]))
            scoreLabel.config(text="Time: " + str(score)+ "s")

This won't work either as it says:

TypeError: 'list' object is not callable

wordlist = words(range(12))

    entry.delete(0, tkinter.END)
    random.shuffle(wordlist)
    label.config(text=str(words[1]))
    scoreLabel.config(text="Time: " + str(score)+ "s")




Aucun commentaire:

Enregistrer un commentaire