Meeting20130226: Anagram.py

File Anagram.py, 554 bytes (added by Simon Cross, 8 years ago)

Anagram game written by Michelle and others.

Line 
1import random
2
3def scramble(word):
4        scrambled = list(word)
5        for x in range(len(word)):
6                r = random.randint(0, len(word) - 1)
7                temp = scrambled[x]
8                scrambled[x] = scrambled[r]
9                scrambled[r] = temp
10        return scrambled
11
12words = ['apple', 'dude', 'croquet', 'granted']
13
14i = random.randint(0,len(words)-1)
15word = words[i] 
16scrambled = scramble(word)
17
18print("Guess the Anagram")
19print("".join(scrambled).upper())
20
21while True:
22        g = raw_input("Guess: ")
23        print(g)
24
25        if g == word: 
26                print('Well done, you win!')
27                break
28        else: 
29                print('Wrong answer dumbass!')