File: adv_hangman.py

package info (click to toggle)
turing 0.11~beta-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,152 kB
  • sloc: python: 103,898; xml: 101; makefile: 50; sh: 29
file content (33 lines) | stat: -rw-r--r-- 698 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
words = ["HELLO", "COMPUTER", "KEYBOARD", "INTERNET", "CORRECT", "HORSE", "BATTERY", "STAPLE"]
word = choice(words)

user = ["_" for _ in word]
tries = 10

while True:    
    if tries <= 0:
        print("You lose!")
        print("The word was: " + word)
        break
        
    print(" ".join(user))
        
    if user == list(word):
        print("You win!")
        break
    
    print("%d tries remaining" % tries)
    
    current = input("? ")[:1].upper()
    
    if not current:
        continue
        
    for i in range(len(user)):
        if word[i] == current:
            user[i] = current
            
    if current not in word:
        tries -= 1
        
    print("\n")