Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100561

Hangman Code.

Newsgroups comp.lang.python
Date 2015-12-17 05:28 -0800
Message-ID <a1d40306-3f82-49a1-8d29-8e2b81f07874@googlegroups.com> (permalink)
Subject Hangman Code.
From trkaplan24@gmail.com

Show all headers | View raw


Hello, I created a python code for a simple hangman game. Was wondering if anyone could edit to help me make it multiplayer so when one person guesses a letter incorrectly, the next player can then guess a letter. 

import time
player1 = raw_input("What is your name Player 1? ")
player2 = raw_input("What is your name Player 2? ")

print "Hello, " + player1, "You get to go first!"
print "Hello, " + player2, "Wait for your turn!"

print "\n"
time.sleep(1)
print "Start guessing..."
time.sleep(0.5)
word = "hockey"
guesses = ''
turns = 10
while turns > 0:
    failed = 0
    for char in word:
        if char in guesses:
            print char,
        else:
            print "_",
            failed += 1
    if failed == 0:
        print "\nYou won"
        break
    print
    guess = raw_input("guess a character:")
    guesses += guess
    if guess not in word:
        turns -= 1
        print "Wrong\n"
        print "You have", + turns, 'guesses left'
        if turns == 0:
            print "You Lose\n"

Thank you!

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Hangman Code. trkaplan24@gmail.com - 2015-12-17 05:28 -0800
  Re: Hangman Code. Denis McMahon <denismfmcmahon@gmail.com> - 2015-12-17 14:12 +0000

csiph-web