connect four: asking for inputs without printing - python

I am making a connect four type game. I am trying to set up the simple playability of the game. I don't get an error, but it does keep sending me into a input when I want it to print out the board. When I type in a number for the column, it doesn't print anything, it just gives me another input I should fill, this continues until i exit the program.. I am trying to stay away from classes, given that I am not very good at programming these yet. I would like to know why this is happening, and what to do to fix it, or if I just need to reprogram the whole thing.
a = [" ", " ", " ", " ", " ", " ", " "]
b = [" ", " ", " ", " ", " ", " ", " "]
c = [" ", " ", " ", " ", " ", " ", " "]
d = [" ", " ", " ", " ", " ", " ", " "]
e = [" ", " ", " ", " ", " ", " ", " "]
f = [" ", " ", " ", " ", " ", " ", " "]
board = [a, b, c, d, e, f] # sets up the board
print("What is player 1's name?")
player1 = input()
print("What is player 2's name?")
player2 = input()
plays = 0
def print_board(): # prints the board
p = 0
for x in board:
for i in x:
print(i, end=" | ")
print()
p += 1
if p != 6:
print("- "*15)
else:
print()
def win(): # defines a boolean if one player has won
i = 0
k = 0
while i != 5:
while k != 6:
if board[i][k] == "o" or board[i][k] == "x":
if board[i+1][k] == board[i][k] == board[i+2][k] == board[i+3][k]:
return False
elif board[i][k] == board[i][k+1] == board[i][k+2] == board[i][k+3]:
return False
elif board[i][k] == board[i+1][k+1] == board[i+2][k+2] == board[i+3][k+3]:
return False
elif board[i][k] == board[i-1][k-1] == board[i-2][k-2] == board[i-3][k-3]:
return False
else:
return True
def play(): # defines the part you play.
if plays % 2 == 0:
player = "o"
else:
player = "x"
print_board()
x = int(input("Where would you like to put your chip?"))
i = 0
while i < 5:
if board[i][x] == " ":
if board[i+1][x] == "x" or board[i+1][x] == "o":
board[i][x] = player
print_board()
if win():
print(player+" won!")
play()
play() # runs the script

try this for your play loop - hopefully it will help you fix the win check also:
def play(): # defines the part you play.
plays = 0
while True:
if plays % 2 == 0:
player = "o"
else:
player = "x"
x = int(input("Where would you like to put your chip?"))
i = 0
for i in range(5):
if board[i][x] == " ":
if board[i+1][x] == "x" or board[i+1][x] == "o":
board[i][x] = player
else:
board[5][x] = player
print_board()
#if win():
# print(player+" won!")
# break
plays += 1
print_board()
play() # runs the script
i commented out the win check because it doesn't work yet

Related

Debugging Maze game in Python

Ive been learning python recently and am currently working on a small terminal game that has a character move through a maze. Im having a bug where my character is getting stuck and not allowed to move into the open spaces. Ive checked that all my movements the correct directions, and im not sure why the character is stuck.
App
played = player.Player(3, 2)
while True:
board.printBoard(played.rowPosition, played.columnPosition)
selection = input("Make a move: ")
if selection == "w":
if board.checkMove(played.rowPosition - 1, played.columnPosition):
played.moveUp()
elif selection == "s":
if board.checkMove(played.rowPosition + 1, played.columnPosition):
played.moveDown()
elif selection == "a":
if board.checkMove(played.rowPosition, played.columnPosition - 1):
played.moveLeft()
elif selection == "d":
if board.checkMove(played.rowPosition, played.columnPosition - 1):
played.moveRight()
else:
print("Invalid key")
if board.checkWin(played.rowPosition, played.columnPosition):
print("You Win!")
break;
Player:
class Player:
def __init__(self, intitalRow, initialColumn):
self.rowPosition = intitalRow
self.columnPosition = initialColumn
def moveUp(self):
self.rowPosition = self.rowPosition - 1
def moveDown(self):
self.rowPosition = self.rowPosition + 1
def moveRight(self):
self.columnPosition = self.columnPosition + 1
def moveLeft(self):
self.columnPosition = self.columnPosition - 1
Gameboard
class GameBoard:
def __init__(self):
self.winningRow = 0
self.winningColumn = 2
self.board = [
[" * ", " * ", " ", " * ", " * ", " * "],
[
" * ",
" ",
" ",
" ",
" * ",
" * ",
],
[
" * ",
" ",
" * ",
" * ",
" ",
" * ",
],
[
" * ",
" ",
" ",
" ",
" ",
" * ",
],
[" * ", " * ", " * ", " * ", " * ", " * "],
]
def printBoard(self, playerRow, playerColumn):
for i in range(len(self.board)):
for j in range(len(self.board[i])):
if i == playerRow and j == playerColumn:
print("P", end="")
else:
print(self.board[i][j], end="")
print("")
def checkMove(self, testRow, testColumn):
if self.board[testRow][testColumn].find("*") != -1:
print("Can't move there!")
return False
return True
def checkWin(self, playerRow, playerColumn):
if playerRow == 0 and playerColumn == 2:
return True
else:
return False
When the selection is "d" the same cell is being checked as when the selection is "a". I think you meant for one of these to use played.columnPosition + 1.

Why my winner check function does not work correctly?

I am working on connect4 game, now I am on winner checking part, but the winnercheck function does not work correctly. How to fix that?
In pycharm editor it says that the variable winner is not used even it is used. And after four same digits verticaly it is not printing who is the winner. I am not sure how to fix it.
Thank you!
from termcolor import colored
field = [[" ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " "]]
def drawField(field):
for row in range(11):
if row % 2 == 0:
rowIndex = int(row / 2)
for column in range(13):
if column % 2 == 0:
columnIndex = int(column / 2)
if column == 12:
print(field[rowIndex][columnIndex])
else:
print(field[rowIndex][columnIndex], end="")
else:
print("|", end="")
else:
print("-------------")
def reset():
for i in range(6):
for b in range(7):
field[i][b] = " "
drawField(field)
Player = 1
def winnerCheck(characters):
maxSQ = 0
char = False
sq = 0
for i in characters:
if i != char:
char = i
sq = 1
else:
sq += 1
if sq > maxSQ:
maxChar = char
maxSQ = sq
if maxChar == "X" or maxChar == "O":
if maxSQ == 4:
winner = 0
if maxChar == "X":
winner = "1"
else:
winner = "2"
print("--------------------------------------")
print("| The winner is player", winner, end="")
print(" |")
print("--------------------------------------")
while True:
rowIndex = False
currentChoice = False
print("Player turn:", Player)
column = int(input("Please enter a column: ")) - 1
if column <= 6:
print(True)
else:
print("You can choose numbers only between 1 and 7 included!")
continue
if Player == 1:
for i in range(5, -1, -1):
if field[0][column] != " ":
print("This column is already filled up! You can't put here anymore!")
full = 0
for b in range(7):
if field[0][b] != " ":
full += 1
if full == 7:
print("There is no winner!")
reset()
break
else:
if field[i][column] != " ":
continue
else:
field[i][column] = colored("X", "red")
drawField(field)
Player = 2
currentChoice = field[i][column]
rowIndex = i
break
else:
for i in range(5, -1, -1):
if field[0][column] != " ":
print("This column is already filled up! You can't put here anymore!")
full = 0
for b in range(7):
if field[0][b] != " ":
full += 1
if full == 7:
print("There is no winner!")
reset()
break
else:
if field[i][column] != " ":
continue
else:
field[i][column] = colored("O", "green")
drawField(field)
currentChoice = field[i][column]
Player = 1
rowIndex = i
break
characters = []
for i in range(6):
print(i)
characters.append(field[i][column])
print(characters)
winnerCheck(characters)
The main issue is in these lines of code:
if maxChar == "X" or maxChar == "O":
and a bit further down:
if maxChar == "X":
These conditions will never be true because your characters are never "X" or "O", but are ANSI escape codes generated by calls to colored, like '\x1b[31mX\x1b[0m'
This is a mixup between "model" and "view" aspects of your code.
The best fix is to not store the result of colored() in your field list. Instead just store plain "X" and "O" values. Then in your drawField function, do the necessary to bring color to your output.
So change:
field[i][column] = colored("X", "red")
To
field[i][column] = "X"
and make the same change for where you have colored("O", "green").
Then in drawField change:
if column == 12:
print(field[rowIndex][columnIndex])
else:
print(field[rowIndex][columnIndex], end="")
to:
ch = field[rowIndex][columnIndex]
output = colored(ch, "red" if ch == "X" else "green")
if column == 12:
print(output)
else:
print(output, end="")
Some other remarks:
Your code will only detect a vertical four in a row. Currently you only pass the information about one column to winnerCheck. You'll want to extend this function to detect also horizontal and diagonal wins...
There is unnecessary code repetition. Like the two blocks that are in the if Player == 1 .... else construct. You should try to make that just one block, as the only difference is what you assign to field[i][column].
As mentioned in comments you have a winner=0 that has no effect, since you immediately assign a different value to it. You can initialise winner in one go:
winner = "1" if maxChar == "X" else "2"
The check for a draw should not require that a user makes an invalid move. You should detect the draw when the last valid move has been made.

Connect4 in Python - Pieces doesn't drop into the board

I'm writing Connect4 in Python. My problem is the function of player_one and player_two don't seem to be working, so the no piece is drop onto the board after player was asked to give input. I also wonder if my code to return the board after player has dropped is correct; I suspect that my present code doesn't return the board updated with a player's piece but being new, I'm not sure what to do.
Please take a look!
def field(field):
for w in range(14):
if w % 2 == 0:
usable_w = int(w/2)
for h in range(15):
if h % 2 == 0:
usable_h = int(h/2)
if h != 14:
print(field[usable_h][usable_w], end="")
else:
print(" ")
else:
print("|", end="")
else:
print("_"*13)
PlayField = [[" ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " "]]
field(PlayField)
def player_one(field):
MoveColumn = int(input("Enter the column 1 - 7\n"))
MoveRow = 6
for row in PlayField:
if MoveColumn >= 1 and MoveColumn <= 7:
if PlayField[MoveColumn-1][MoveRow] == " ":
PlayField[MoveColumn-1][MoveRow] = "X"
break
MoveRow -= 1
return field(PlayField)
else:
print("Column outside range, please enter valid move")
def player_two(field):
MoveColumn = int(input("Enter the column 1 - 7\n"))
MoveRow = 6
for row in PlayField:
if MoveColumn >= 1 and MoveColumn <= 7:
if PlayField[MoveColumn-1][MoveRow] == " ":
PlayField[MoveColumn-1][MoveRow] = "O"
break
MoveRow -= 1
return field(PlayField)
else:
print("Column outside range, please enter valid move")
def launch_play():
while True:
Player = 1
print("Player's turn", Player)
player_one(field)
player_two(field)
launch_play()
Well, your player_... functions contain suitable statements, but in an unsuitable order; and since they operate on the global PlayField, returning it is pointless. Besides that, it's ugly having two nearly identical functions. A rearranged variant where the only difference between player one and two is passed as an argument (instead of the useless field) works as you expect:
def player(xo):
while (MoveColumn := int(input("Enter the column 1 - 7\n"))) < 1 or \
MoveColumn > 7:
print("Column outside range, please enter valid move")
MoveRow = 6
for row in PlayField:
if PlayField[MoveColumn-1][MoveRow] == " ":
PlayField[MoveColumn-1][MoveRow] = xo
field(PlayField)
break
MoveRow -= 1
In your launch_play loop you can now call
player('X')
player('O')
Now it's up to you to complete the program by checking when the game is over.
I came up with two solutions (before you modified the codes) to prevent players' turn from changing, but which couldn't work:
def player(xo):
while MoveColumn := int(input("Enter the column 1 - 7\n")):
MoveRow = 6
for row in PlayField:
if PlayField[MoveColumn-1][MoveRow] == " ":
PlayField[MoveColumn-1][MoveRow] = xo
field(PlayField)
break
Return True
MoveRow -= 1
else:
print("Column outside range, please enter valid move")
Return False
def launch_play():
while True:
Player = 'X'
print("Player's turn", Player)
player('X')
Player = '0'
print("Player's turn", Player)
player('0')
launch_play()
The other solution is to introduce player variables in the player functions (also didn't work) :
def player(xo):
while MoveColumn := int(input("Enter the column 1 - 7\n")):
MoveRow = 6
Player = 'X'
for row in PlayField:
if PlayField[MoveColumn-1][MoveRow] == " ":
PlayField[MoveColumn-1][MoveRow] = xo
field(PlayField)
break
MoveRow -= 1
Player = '0'
else:
print("Column outside range, please enter valid move")

Not recognizing tie in Tic Tac Toe AI

I am building a Tic Tac Toe AI. Here are the rules for the AI:
If there is a winning move, play it.
If the opponent has a winning move, block it.
Otherwise, play randomly.
Here's the code:
# main.py
# Prorities:
# - If there is a winning move, play it
# - If the opponent has a winning move, block it.
# - If nothing to block, make a random move.
import random
import time
import copy
boxes = []
for i in range(3):
row = []
for j in range(3):
row.append(" ")
boxes.append(row)
def printBoard():
to_print = ""
to_print += " " + boxes[0][0] + " | " + boxes[0][1] + " | " + boxes[0][2] + " \n"
to_print += "---+---+---\n"
to_print += " " + boxes[1][0] + " | " + boxes[1][1] + " | " + boxes[1][2] + " \n"
to_print += "---+---+---\n"
to_print += " " + boxes[2][0] + " | " + boxes[2][1] + " | " + boxes[2][2] + " \n"
return to_print
turn = random.randint(1, 2)
if turn == 1:
coin = "you (X)"
else:
coin = "the AI (O)"
print("The coin flip shows", coin, "will go first!")
input("Press Enter to begin! ")
def checkWin(boxes):
win = False
who = " "
for i in range(3):
if boxes[i][0] == boxes[i][1] and boxes[i][1] == boxes[i][2]:
who = boxes[i][0]
if who != " ":
win = True
for i in range(3):
if boxes[0][i] == boxes[1][i] and boxes[2][i] == boxes[1][i]:
who = boxes[0][i]
if who != " ":
win = True
if boxes[0][0] == boxes[1][1] and boxes[1][1] == boxes[2][2]:
who = boxes[0][0]
if who != " ":
win = True
if boxes[0][2] == boxes[1][1] and boxes[1][1] == boxes[2][0]:
who = boxes[0][2]
if who != " ":
win = True
return win, who
def checkTie(boxes):
for row in boxes:
for box in boxes:
if box != "X" and box != "O":
return False
return True
def checkMove(boxes, player):
for i in range(3):
for j in range(3):
if boxes[i][j] != "X" and boxes[i][j] != "O":
boxCopy = copy.deepcopy(boxes)
boxCopy[i][j] = player
win, who = checkWin(boxCopy)
if win:
return True, i, j
return False, 0, 0
while True:
print("Check 1")
win, who = checkWin(boxes)
if win and who == "X":
print("Player X has won.")
print(" ")
print(printBoard())
break
elif win and who == "O":
print("Player O has won.")
print(" ")
print(printBoard())
break
elif checkTie(boxes) == True:
print("It has been concluded as a tie.")
break
print("Check 2")
if turn == 1:
print("")
print(printBoard())
row = (int(input("Pick a row to play: ")) -1)
col = (int(input("Pick a column to play: ")) -1)
if ((row < 4 and row > -1) and (col < 4 and col > -1)) and (boxes[row][col] == " "):
boxes[row][col] = "X"
turn = 2
else:
print("Sorry, that is not allowed.")
print(" ")
# Prorities:
# - If there is a winning move, play it
# - If the opponent has a winning move, block it.
# - If nothing to block, make a random move.
else:
print("")
print(printBoard())
print("[*] AI is choosing...")
time.sleep(1)
row = random.randint(0, 2)
col = random.randint(0, 2)
winMove, winRow, winCol = checkMove(boxes, "O")
lossMove, lossRow, lossCol = checkMove(boxes, "X")
if winMove and (boxes[winRow][winCol] != "X" and boxes[winRow][winCol] != "O"):
boxes[winRow][winCol] = "O"
turn = 1
print("Statement 1: Win play")
elif lossMove and (boxes[lossRow][lossCol] != "X" and boxes[lossRow][lossCol] != "O"):
boxes[lossRow][lossCol] = "O"
turn = 1
print("Statement 2: Block play")
elif boxes[row][col] != "X" and boxes[row][col] != "O":
boxes[row][col] = "O"
turn = 1
print("Statement 3: Random play")
else:
print("Statement 4: None")
print("Check 3")
The problem occurs when there is a tie. Either the function checkTie(), or the if statement isn't working. You might see a couple print('Check #') every once in a while. When you run the code and it's a tie, it shows all the checks going by. Which means it is passing through the check. When there is a tie, it just keeps doing the loop and repeating its turn but not making a move.
What is the mistake and how can I do this correctly?
I think your function should be
def checkTie(boxes):
for row in boxes:
for box in row:
if box != "X" and box != "O":
return False
return True
You mistyped ( I think) boxes for row in the second for statement.
def checkTie(boxes):
if any(" " in box for box in boxes):
return False
return True
Change your checkTie function to this
The rest is all good.

Python Hangman not working

So, I've finished my Hangman project for a coding class and it's stuck in a loop where it just keeps asking if you want to play, after that it defines the word to play but it also TELLS you which word to play you're going to play. I think the chained whiles and ifs have some wrong variables.
So, I beg for your help.
__author__ = 'Rodrigo Cano'
#Modulos
import random
import re
#Variables Globales
intentos = 0
incorrectos = 0
palabras = [(1,"disclosure"),(1,"thenational"),(1,"foals"),(1,"skepta"),(1,"shamir"),(1,"kanye"),
(1,"fidlar"),(1,"lcdsoundsystem"),(1,"lorde"),(1,"fkatwigs"),(1,"miguel"),(1,"rtj"),
(1,"boniver"),(1,"strokes"),(2,"vaporwave"),(2,"witchouse"),(2,"shoegaze"),(2,"memerap"),
(2,"paulblartisoursaviour"),(3,"glockenspiel"),(3,"aesthetic"),(3,"schadenfreude"),
(3,"bonvivant"),(3,"swag"),(3,"jue")]
Ascii_Art =[""]
Dibujo = ' '
palabra_a_jugar = ''
Array_Palabra = []
Nuevas_Letras = ''
letras = []
Vidas = 0
i = len(Array_Palabra)
#Funciones
def Definir_Palabra():
eleccion = int(input("Bienvenido, que categoria quiere usar:"
'\n'"1 - Musica que Escuche Mientras Lo Hacia"
'\n'"2 - Generos Musicales"
'\n'"3 - Palabras Pretenciosas"))
palabras_escogidas = [i for i in palabras if eleccion in i ]
palabra_a_jugar = str(palabras_escogidas[random.randint(0,len(palabras_escogidas))].__getitem__(1))
Array_Palabra = len(palabra_a_jugar) * ['*']
return palabra_a_jugar, Array_Palabra
def Letras_En_Palabra(letra):
letras = [i for i, x in enumerate(palabra_a_jugar) if x == letra]
for i in range (0, len(letras)):
Array_Palabra[letras] = letra
return letras,Array_Palabra
def Letras_Jugadas(letra):
for i in range(0,len(Nuevas_Letras)):
Nuevas_Letras = re.findall(letra,Nuevas_Letras[i])
if Nuevas_Letras != []:
return 1
return Nuevas_Letras
def Eleccion():
Choice = input("Quiere Jugar?")
if Choice == 'si':
Choice = 1
elif Choice == 'no':
Choice = 0
return Choice
# Juego
Choice = Eleccion()
def Juego(Choice):
i = len(Array_Palabra)
while Choice == 1:
print(Definir_Palabra())
while i != 0 :
tiro = str.lower(input("adivine una letra"))
if Letras_Jugadas(tiro) != 1:
Nuevas_Letras = Nuevas_Letras + tiro
letras = Letras_En_Palabra(tiro)
if Letras_Jugadas(tiro) != []:
i = len(letras) - 1
print("Letras Utilizadas",Nuevas_Letras)
print(Letras_En_Palabra(tiro))
else:
Vidas = Vidas + 1
Dibujo += Ascii_Art[Vidas]
print("WROOOONG")
print(Dibujo)
print("Letras Utilizadas",Nuevas_Letras)
if Vidas ==9:
i = 0
else:
print("Letra ya Juagada",Nuevas_Letras)
Eleccion()
Juego(Choice)
The last line in your Juego should be Choice = Eleccion(), otherwise, you're not actually changing the value of Choice, so the loop continues indefinitely.
def Juego(Choice):
i = len(Array_Palabra)
while Choice == 1:
print(Definir_Palabra())
while i != 0 :
tiro = str.lower(input("adivine una letra"))
if Letras_Jugadas(tiro) != 1:
Nuevas_Letras = Nuevas_Letras + tiro
letras = Letras_En_Palabra(tiro)
if Letras_Jugadas(tiro) != []:
i = len(letras) - 1
print("Letras Utilizadas",Nuevas_Letras)
print(Letras_En_Palabra(tiro))
else:
Vidas = Vidas + 1
Dibujo += Ascii_Art[Vidas]
print("WROOOONG")
print(Dibujo)
print("Letras Utilizadas",Nuevas_Letras)
if Vidas ==9:
i = 0
else:
print("Letra ya Juagada",Nuevas_Letras)
"""
>>>> CHANGED <<<<
"""
Choice = Eleccion()
Otherwise, the way you had it simply calls the function Eleccion but doesn't return the value to the Choice variable in scope of Juego function.
Just need to indent :)
import random
# defining the main method
def main():
print "Hello Welcome to Python Hangman!!!"
random_word()
user_input()
# defining the dictionary_list to be used as the guessing word
def random_word():
dictionary_list= ["ant", "bath", "car", "dog", "electric", "foil", "grape", "heat", "ice", "jolly",
"knight", "lemon", "money", "need", "open", "park", "quote", "rough", "salty",
"teach", "under", "village", "warmth", "xavier", "yelp", "zipper"]
# making rand global so it can be used within deifferent functions
global rand
# randomly choosing a word from the dictionary_list and assign to the variable rand
rand = random.choice(dictionary_list)
return rand
# user guessing
def user_input():
guesses = 0
wrong_guess = 0
guess_left = 10
correct_letters_list = ""
wrong_letters_list =""
print "You have \033[1;34;15m 10 \033[0;30;15m guesses"
#getting the length of the word
length = len(rand)
print "The word is: " + "\033[1;35;15m" + str(length) + "\033[0;30;15m" + " characters long"
# loops around until the user has used all their 6 guesses are used up
while guesses < 10 :
guess = raw_input("Guess a Letter [a-z]: ").lower()
# stop case sensitivity
# if the letter guessed by the user is in rand string print correct else print wrong
if guess in rand:
correct_letters_list += guess
print "\033[1;32;15mcorrect"
print "correct letters:"
print "\033[0;30;15m" + correct_letters_list
print "incorrect letters:"
print "\033[0;30;15m" + wrong_letters_list
# each time the user guesses + 1 to the guesses tally
guesses +=1
guess_cal = guess_left - guesses
print "You have: " + str(guess_cal) + " guesses left"
# if rand contains guess more than once tell user
if rand.count(guess) > 1 :
print "The word contains the letter " + str(guess) + " " + "\033[1;36;15m" + str(rand.count(guess)) + "\033[0;30;15m" + " times"
else:
wrong_letters_list += guess
print "\033[1;31;15mwrong"
print "incorrect letters:"
print "\033[0;30;15m" + wrong_letters_list
print "correct letters:"
print "\033[0;30;15m" + correct_letters_list
guesses += 1
guess_cal = guess_left - guesses
print "You have: " + str(guess_cal) + " guesses left"
wrong_guess += 1
if wrong_guess == 1:
print "________ "
print "| | "
print "| "
print "| "
print "| "
print "| "
if wrong_guess == 2:
print "________ "
print "| | "
print "| 0 "
print "| "
print "| "
print "| "
if wrong_guess == 3:
print "________ "
print "| | "
print "| 0 "
print "| / "
print "| "
print "| "
if wrong_guess == 4:
print "________ "
print "| | "
print "| 0 "
print "| /| "
print "| "
print "| "
if wrong_guess == 5:
print "________ "
print "| | "
print "| 0 "
print "| /|\ "
print "| "
print "| "
if wrong_guess == 6:
print "________ "
print "| | "
print "| 0 "
print "| /|\ "
print "| / "
print "| "
if wrong_guess >= 7:
print "________ "
print "| | "
print "| 0 "
print "| /|\ "
print "| / \ "
print "| "
choice = raw_input("Do you wish to guess the word? (Y/N): ").lower()
if choice == 'y':
word = raw_input("Please enter the word: ").lower()
if word == rand:
print "Well Done you Guessed Correctly, the word was: " + rand
# if the user has guessed correctly + 10 to the guesses tally to end the game
guesses += 10
else:
print "Incorrect, Game Over!! The word was: " + rand
guesses += 10
# if user chooses n continue with the game
if choice == 'n':
continue
# if the user has used up all their 10 guesses print Game Over!!
if guesses == 10:
print "End of Game you ran out of guesses!!!"
if __name__ == "__main__":
main()

Categories

Resources