Extra credit


#1

python

im stuck on extra credit how do i make a second ship and how do i make the board show up after the guess is put in.



            this is my code

from random import randint

board = []

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

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) - 1)

for turn in range(5):
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))

if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sunk my battleship!" 
    print "you win"
    break
else:
    if (guess_row < 0 or guess_row > 9) or (guess_col < 0 or guess_col > 9):
        print "Oops, that's not even in the ocean."
    elif(board[guess_row][guess_col] == "X"):
            print "You guessed that one already."
    else:
        print "You missed my battleship!"
        "try again"
        board[guess_row][guess_col] = "X"
if turn == 5:
    print "Game Over"
    print "Turn", turn +1

#2

That's why it is called extra credit... Something for us to do on our own, under our own steam. You don't have to do it today, and perhaps after you finish this track would be the time to come back to this.

Go ahead an submit this lesson. There is no lesson checker so you can get credit for completing the module.


#3

i know but i'm doing a project and want to use this as my project so i want to make it better.


#4

Projects are fine, but in many cases it is better to finish the track so you have more tools at your disposal and don't fall to the whims of others whose suggestions may be good, but may not be easily understood or visualized.


#5

ok thx i really appreciat it hope not to need to ask any more q thx.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.