-
Notifications
You must be signed in to change notification settings - Fork 1
/
hangman.py
39 lines (35 loc) · 915 Bytes
/
hangman.py
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
34
35
36
37
38
39
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 2 14:26:18 2016
@author: gu32hej
"""
import random
words = ['haus','baum','auto','baustelle']
word = words[random.randint(0,len(words)-1)]
Leben = 6
solution = []
for i in word:
solution.append('.')
print ''.join(solution)
while ''.join(solution) != word:
if Leben == 0:
print 'Sorry, verloren. Das Wort war: '+word
break
letter = raw_input('Buchstabe eingeben: ')
if len(letter)!=1:
print 'Bitte nur einen Buchstaben eingeben'
continue
else:
found = False
for i in range(len(word)):
if letter == word[i]:
found = True
solution[i]=letter
if found:
print solution
continue
else:
print 'Leider falsch!'
Leben-=1
print 'Du hast noch %s Leben.'%Leben
print 'Prima! Gewonnen!'