[TiLUG] Fwd: Impiccato in python

Nanomad condellog@gmail.com
Ven 23 Gen 2009 16:56:21 CET


Mi ero dimenticato l'allegato :(



-- 
Member of TiLUG, Ticinum Linux User Group, Pavia, Italy

Currently Running:
Ubuntu "Intrepid Ibex" on Desktop PCs (2 x P4 1.4Ghz)
Ubuntu "Intrepid Ibex" on Laptop (Centrino 2Ghz)
-------------- parte successiva --------------
import random
import time
from math import floor


def print_status():
    print "Indovinami!"
    for x in word:
        if(x not in dette):
            print "_ ",
        else:
             print x,
             print ' ',
    print ''
    print "Gia' dette: ",
    print dette
    print "Vite rimaste: ",
    print lives
    return

def get_and_analyze_input(found,lives):
    letto = str(raw_input("Inserisci una lettera "))
    print len(letto)
    if(letto[0] in dette):
        return (found,lives)
    if(letto[0] in word):
        found+=word.count(letto[0])
    else:
        lives-=1
    dette.append(letto[0])
    return (found,lives)

file = open("file.txt")
voc = file.read().split('\n')
file.close()
random.seed=time.time()
num = int(random.random()*len(voc))
word = voc[num]
dette=[]
lives = 5
found = 0
while(found!=len(word) and lives>0):
    print_status()
    (found,lives)=get_and_analyze_input(found,lives)
    print ' '
    print ' '
if(lives!=0):
    print "Hai vinto!!!!!"
else:
    print "Hai perso!!!"

print "La parola era: ",
print word
-------------- parte successiva --------------
cane
cavallo
casa
pippo
pluto
gatto


Maggiori informazioni sulla lista TiLUG