Advertisement
Filly

Hola, mundo!

Jun 15th, 2011
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. from random import choice
  2.  
  3.  
  4. STATE = ['''       _____
  5.      |     |
  6.            |
  7.            |
  8.            |
  9.          __|_''',
  10.           '''       _____
  11.      |     |
  12.      O     |
  13.            |
  14.            |
  15.          __|_''',
  16.           '''       _____
  17.      |     |
  18.      O     |
  19.      |     |
  20.            |
  21.          __|_''',
  22.           '''       _____
  23.      |     |
  24.      O     |
  25.      |     |
  26.     /      |
  27.          __|_''',
  28.           '''       _____
  29.      |     |
  30.      O     |
  31.      |     |
  32.     / \   |
  33.          __|_''',
  34.           '''       _____
  35.      |     |
  36.      O     |
  37.     /|     |
  38.     / \   |
  39.          __|_''',
  40.           '''       _____
  41.      |     |
  42.      O     |
  43.     /|\   |
  44.     / \   |
  45.          __|_''']
  46.  
  47.  
  48. LANGUAGES = {'hola mundo': 'español', 'hello world': 'inglés',
  49.              'hallo welt': 'alemán', 'bonjour monde': 'francés',
  50.              'ciao mondo': 'italiano', 'labas pasauli': 'lituano'}
  51.  
  52.  
  53. def guessing():
  54.     print('¿Qué letra está en la frase?')
  55.     guess = input().lower()
  56.     return guess
  57.  
  58.  
  59. def is_in_word(picture, answer, blank, dictionary):
  60.     state = 0
  61.     while state < 6:
  62.         print(picture[state])
  63.         print('\n      %s\n\n' %blank)
  64.         if blank == answer:
  65.             win(answer, dictionary)
  66.             break
  67.         guess = guessing()
  68.         if guess.lower() == answer:
  69.             blank = answer
  70.         elif guess.lower() in answer:
  71.             print(guess + ' está en la frase.')
  72.             for i, letter in enumerate(answer):
  73.                 if guess.lower() == letter:
  74.                     blank = blank[:i] + letter + blank[i + 1:]
  75.         elif guess.lower() not in answer:
  76.             print(guess + ' no está en la frase.')
  77.             state += 1
  78.     if state == 6:
  79.         lose(answer, dictionary, picture)
  80.  
  81.  
  82. def win(answer, dictionary):
  83.     print('\n¡Bien! La respuesta era \'%s\', que significa \'hola mundo\' \
  84. en %s.\n' % (answer, dictionary[answer]))
  85.     print('¡Hola, PyAr! Soy Filly, y este fue mi "Hola, mundo!". :)\n')
  86.  
  87.  
  88. def lose(answer, dictionary, picture):
  89.     print(picture[6])
  90.     print('\n      %s\n' %blank)
  91.     print('\nGame over. La respuesta era \'%s\', que \
  92. significa \'hola mundo\' en %s.\n' % (answer, dictionary[answer]))
  93.  
  94.  
  95. play = True
  96.  
  97. while play:
  98.     print('\n\nF I L L Y\' S  A W E S O M E  H A N G M A N  G A M E \
  99. (???)\n')
  100.  
  101.     word = choice(list(LANGUAGES.keys()))
  102.     space = word.find(' ')
  103.     blank = '_' * len(word[:space]) + ' ' + '_' * len(word[space + 1:])
  104.  
  105.     is_in_word(STATE, word, blank, LANGUAGES)
  106.  
  107.     ask = input('¿Jugar de nuevo? Y/N: ')
  108.     if ask.lower() in ('yes', 'y'):
  109.         play = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement