Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,671 members, 7,820,357 topics. Date: Tuesday, 07 May 2024 at 01:32 PM

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

Nairaland Forum / Science/Technology / Programming / Python Pros. . .please Help!!! (1076 Views)

What Are The Main Pros And Cons Of Online Marketplace Platform / Java Codes For Beginners And Pros (relaxation Thread) (2) (3) (4)

(1) (Reply) (Go Down)

Python Pros. . .please Help!!! by Ignaz(m): 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(m): 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(m): 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(m): 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

2 Likes

Re: Python Pros. . .please Help!!! by Ignaz(m): 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)

Method 2go Used To Charge Their Users For Gocredit / I Need Urgent Help In Creating 3line Responsive Menu / How Do I Setup Webhost Mail Server

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.