1 Replies - 1213 Views - Last Post: 15 April 2012 - 04:53 PM Rate Topic: -----

#1 asli1991  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-April 12

a hangman script show letters

Posted 14 April 2012 - 09:56 AM

this is my code :
i have to print only the letters in (*) and symbols must automaticly printed.

guesses =''

    while turns > 0:
          missed = 0
          letters = [ 'a', 'b','c', 'd', 'e', 'f' , 'g', 'h','i', 'j', 'k', 'l','m','n',
                    'o', 'p','q', 'r', 's', 't', 'u', 'v','w' , 'x', 'y', 'z']
          
          ster = ''
          for letter in secret:
            if letter in guesses:
              ster += letter
              #print (letter)
            else:
              ster += '*'
              missed += 1
          #print (letter)
          print (ster , "aantal kansen: ", turns)


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

ESPECIALLY in Python, where whitespace is of paramount importance!

This post has been edited by JackOfAllTrades: 14 April 2012 - 11:55 AM


Is This A Good Question/Topic? 0
  • +

Replies To: a hangman script show letters

#2 wordswords  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 76
  • View blog
  • Posts: 272
  • Joined: 17-December 11

Re: a hangman script show letters

Posted 15 April 2012 - 04:53 PM

Here is my version, it is in English, hope you can read it:

secret = "happiness"
guesses =''
next_guess = ''
turns = 20

while turns > 0:
  missed = 0
  letters = [ 'a', 'b','c', 'd', 'e', 'f' , 'g', 'h','i', 'j', 'k', 'l','m','n','o', 'p','q', 'r', 's', 't', 'u', 'v','w' , 'x', 'y', 'z']

  ster = ''
  while len(next_guess) != 1:
          print("Your next guess?\n")
          next_guess = raw_input()

  guesses += next_guess
  next_guess = ''
  for letter in secret:
    if letter in guesses:
      ster += letter
    else:
      ster += '*'
      missed += 1
  print (ster , "Hangman : ", turns)
  if missed == 0:
        print("Correct!")
        break
  turns -= 1

if turns < 1:
        print("Sorry, you lose!")


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1