Welcome, guest | Sign In | My Account | Store | Cart

Classic Hangman on console, check how hang the man with codes! Click 'download' and left click the .py file, have fun!

Python, 129 lines
  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
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python
# -*-coding:utf-8-*-
import random
import time
from time import sleep

nesne="HANGMAN"
by="##Veysel Nantu##"
date="28.11.2014"
simge="-"*50
bos=""*5
bilgi="""            You will earn 50 points if you know a character
            and you will lose 25 points if your answer is wrong.
            If you give 5 wrong answers you will lose."""
print("{:^80}\n{:^80}\n{:^80}\n{:^80}\n{}".format(nesne,by,date,simge,bos))
print(bilgi)
print("{:^80}\n{:^80}\n{:^80}".format(bos,simge,bos))

kelimeler = ["ability","about","above","absolute","accessible","accommodation",
             "accounting","beautiful","bookstore","calculator","clever","engaged",
             "engineer","enough","handsome","refrigerator","opposite","socks",
             "interested","strawberry","backgammon","anniversary","confused",
             "dangerous","entertainment","exhausted","impossible","overweight",
             "temperature","vacation","scissors","accommodation","appointment",
             "decrease","development","earthquake","environment","brand",
             "environment","necessary","luggage","responsible","ambassador",
             "circumstance","congratulate","frequent",]
secim = random.choice(kelimeler)
tablov=[]
tablov.append("-"*len(secim))
tablo=[]
for i in tablov:
    for h in i:
        tablo.append(h)
print("Our word has {} letters.".format(len(secim)),' '.join(tablo))
print(""*7)
c="""  _________
  |
  |"""
c1="\n  O"
c2="\n \|/"
c3="\n  |"         # <---- CAREFULL HERE :-)
c4="\n / \ "
cson=""
depo=""
depo1=""
a=len(depo)
can=5
puan=0
olmazlar="+/ 1234567890*-_?.,"
while True:
    if len(depo)==len(secim): #depo uzunlugu kelimenin uzunluguna e┼čitse
        print("You won! Word: {} Your score: {}".format(secim,puan))
        print("Please press 'Enter' for quit..")
        break
    if can==0:
        print("\nYou lose...")
        sleep(0.9)
        print ("Your score: {}".format(puan))
        sleep(0.9)
        print ("The word that you couldnt answer: {}".format(secim))
        sleep(0.9)
        print("Please press 'Enter' for quit..")
        break

    x=input("\nPlease enter a letter: ")
    if 1<len(x):
        print ("\nYou can enter only 1 letter..")
        continue
    if x in olmazlar:
        print("\nIt's not even a letter!")
        continue
    if x in depo:
        print("You used this letter before!")
        continue
    if x in depo1:
        print("You used this letter before!")
        continue
    if x in secim and not x in depo:
        puan+=50*secim.count(x)
        print("Letter {} is counted {} times.".format(x,secim.count(x)))
        sleep(0.7)
        for sayi, oge in enumerate(secim):
            if 2 <=secim.count(oge) and x==oge:
                depo+=x
                a+=secim.count(oge)
                if tablo[sayi]=="-": 
                    tablo[sayi]=x
                print("In line {} .".format(sayi+1))
                sleep(0.7)
            if secim.count(oge)==1 and x==oge:
                depo+=x
                a+=secim.count(oge)
                if tablo[sayi]=="-":
                    tablo[sayi]=x
                print("In line {} .".format(sayi+1))
                sleep(0.7)
        print("\nWord:",' '.join(tablo))
        sleep(0.7)

    else:
        depo1+=x
        can-=1
        puan-=25
        print("\nThis letter {} not in our word! {} healt left.".format(x,can))
        sleep(0.7)
        print("\nWord:",' '.join(tablo))
        sleep(0.7)
        if can==4:
            cson+=str(c)
            print(cson)
        if can==3:
            cson+=str(c1)       # WE STARTING HANG THE MAN HERE :-)
            print(cson)      
        if can==2:          
            cson+=str(c2)
            print(cson)
        if can==1:
            cson+=str(c3)
            print(cson)
        if can==0:
            cson+=str(c4)
            print(cson)


try:
    input()
except SyntaxError:
    pass