₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,120 members, 8,420,471 topics. Date: Thursday, 04 June 2026 at 08:52 PM

Toggle theme

Python Pros. . .please Help!!! - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPython Pros. . .please Help!!! (1199 Views)

1 Reply (Go Down)

Python Pros. . .please Help!!! by Ignaz(op): 8:33pm On Sep 30, 2015
from random import randint

board = []

for x in range(5):
. board.append(["O"] * 5)

def print_board(board):
. for row in board:
. print " ".join(row)

print "Let's play Battleship!"
print_board(board)

def random_row(board):
. return randint(0, len(board) - 1)

def random_col(board):
. return randint(0, len(board[0]) - 1)

ship_row = random_row(board)
ship_col = random_col(board)
print ship_row
print ship_col

# Everything from here on should go in your for loop!
# Be sure to indent four spaces!
for turn in range(4):
. print "turn", turn + 1
guess_row = int(raw_input("Guess Row:"wink)
guess_col = int(raw_input("Guess Col:"wink)

if guess_row == ship_row and guess_col == ship_col:
. print "Congratulations! You sunk my battleship!"
. break
else:
. if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4):
. print "Oops, that's not even in the ocean."
. elif(board[guess_row][guess_col] == "X"wink:
. print "You guessed that one already."
. else:
. print "You missed my battleship!"
. board[guess_row][guess_col] = "X"
. if turn==3:
. print 'Game Over'
# Print (turn + 1) here!
print 'Turn', turn+1
print_board(board)

. # Print (turn + 1) here!
i am stuck. the problem here is the bolded word in the quote above. where do i place the break? i intend to break the loop after the first if statement
any solution is sincerely appreciated
Re: Python Pros. . .please Help!!! by spikesC(m): 8:38pm On Sep 30, 2015
Use pastebin to share your code then post the link here. Spaces are very important in python so it would be hard for anyone to understand your code here
Re: Python Pros. . .please Help!!! by Ignaz(op): 8:39pm On Sep 30, 2015
spikesC:
Use pastebin to share your code then post the link here. Spaces are very important in python so it would be hard for anyone to understand your code here
what is pastebin please?
Re: Python Pros. . .please Help!!! by spikesC(m): 8:41pm On Sep 30, 2015
Ignaz:
what is pastebin please?
http://pastebin.com

Make sure you select syntax highlighting as python
Re: Python Pros. . .please Help!!! by Ignaz(op): 8:45pm On Sep 30, 2015
spikesC:
http://pastebin.com

Make sure you select syntax highlighting as python
http://pastebin.com/p0Twmuit
Re: Python Pros. . .please Help!!! by Ignaz(op): 9:19pm On Sep 30, 2015
http://pastebin.com/GaNf8v2w


anybody? please help correct the BREAK loop
Re: Python Pros. . .please Help!!! by spikesC(m): 10:26pm On Sep 30, 2015
Ignaz:
http://pastebin.com/GaNf8v2w


anybody? please help correct the BREAK loop
Fixed: http://pastebin.com/vFcWdKRz

Problem was with indentation
Re: Python Pros. . .please Help!!! by Ignaz(op): 8:09pm On Oct 01, 2015
spikesC:
Fixed: http://pastebin.com/vFcWdKRz

Problem was with indentation
thanks alot Boss
so relieved to see it finally work out
1 Reply

What Are The Main Pros And Cons Of Online Marketplace PlatformJava Codes For Beginners And Pros (relaxation Thread)234

All Programmers Please Help Me About ProgrammingGoogle Parners With Udacity To Provide Android Programming Course For BeginnersData Science