Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- from random import *
- player_score = 0
- computer_score = 0
- def hangedman(hangman):
- graphic =[ """ base""","""first attempt made""", """ second attempt""","""third attempt ""","""fourth attempt """,""" fifth attempt """,""" make your sixth and final attempt!"""]
- print graphic[hangman]
- return
- def start():
- print "Let's play a game of Linux Hangman"
- while game():
- pass
- scores()
- def game():
- dictionary=["gentoo", "ubuntu", "arch", "slackware", "fedora", "suse"]
- word = choice(dictionary)
- word_length = len(word)
- clue = word_length * ["_"]
- tries = 6
- letters_tried = ""
- guesses = 0
- letters_right = 0
- letters_wrong = 0
- global computer_score, player_score
- while (letters_wrong != tries) and ("".join(clue) != word):
- letters=guess_letter()
- if len(letter)==1 and letter.isalpha():
- if letters_tried.find(letter) != -1:
- print "You've already picked", letter
- else:
- letters_tried = letters_tried + letter # what about using letters_tried += 1 instead ???
- first_index=word.find(letter)
- if first_index == -1:
- letters_wrong += 1
- print "Sorry,", letter, "isn't what we're looking for."
- # what about swapping lines 40 with 41 - - would that behave the same way?
- else:
- print "Congratulations", letter, "is correct."
- for i in range(word_length):
- if letter == word[i]:
- clue[i] = letter
- else:
- print "Go ahead, choose another."
- hangedman(letters_wrong)
- print " ".join(clue)
- print "Guesses: ", letters_tried
- if letters_wrong == tries:
- print "Game Over"
- print "The word was, ", word
- computer_score += 1
- break
- if "".join(clue) == word:
- print "You Win!"
- print "The word was, ", word
- player_score += 1
- break
- return play_again()
- def guess_letter():
- print
- letter = raw_input("Take a guess at the mystery word.")
- letter.strip()
- letter.lower()
- print
- return letter
- def play_again():
- answer = raw_input("Would you like to play again? y/n:")
- if answer in ("y", "Y", "yes", "Yes", "Of course!"):
- return answer
- else:
- print "Thank you very much for playing our game. See you next time!"
- def scores():
- global player_score, computer_score
- print "HIGH SCORES"
- print "Player: ", player_score
- print "Computer: ", computer_score
- if __name__ == '__main__':
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement