|
Programmer
Join Date: Nov 2005
Location: Estonia
Posts: 97
Rep Power: 0 
|
Thanks Arevos! It works perfectly now!
The code is here (LOL at the MIT license):
'''
The MIT License
Copyright (c) 2006 Ville Sokk (Commodore)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
NOTE: the program was taken to the final state thanks to the help of Arevos from http://www.programmingforums.org
'''
import random
import sys
import time
filer=open('words.txt', 'r')
words=filer.readlines() # puts the words in a list
orgwordstring=random.choice(words).strip() # chooses a random word from the list
orgword=list(orgwordstring)
newword=list(orgword[0]+((len(orgword)-2)*'_')+orgword[-1])
life=10
while newword!=orgword and life!=0:
print 'The word is: %s' % (' '.join(newword))
print ''
what=str(raw_input('Type in a letter that you think should be in that word or leave empty if you want to quit: '))
if what=="":
sys.exit()
if what not in orgword:
life=life-1
print 'Sorry this letter isn\'t included in the word. You have lost a life. You have %d lives left' % (life)
else:
for position, letter in enumerate(orgword):
if letter == what:
newword[position]=letter
filer.close()
if life==0:
print 'You have 0 lives left. You didn\'t guess the word.'
else:
print 'Gongratulations! You have guessed the word! It is ', ''.join(orgword)
words.remove(''.join(orgword)+'\n')
words=''.join(words)
filew=open('words.txt', 'w')
filew.writelines(words) # writes the words back to the file, now without the guessed word
filew.close()
exiter=raw_input('Press enter to quit: ')
while exiter!='':
exiter=raw_input('I said press ENTER! ')
if exiter=='':
sys.exit()
I have to finish my other (non-programming) projects and then I can try other peoples versions too!
|