Codecademy - Python: Tutorial #18

preview_player
Показать описание
Enroll for coding exercises, projects, tutorials, and courses...

Unit 7 - Lists and Functions
===========================================
0:58 -- 8. ...and Seek!
5:49 -- 9. It's Not Cheating--It's Debugging!
7:59 -- 10. You win!
11:38 -- 11. Danger, Will Robinson!!
15:32 -- 12. Bad Aim
===========================================

This is part 18 of the Codecademy Python Walkthrough Tutorial. We continue working on our Battleship program!

======================= ABOUT PYTHON CODECADEMY SERIES =================

The target audience is beginners or developers looking to pick up Python. I also emphasize the importance of writing good code and I go through the first part really fast.

I will literally be going through every single thing and breaking it down for you so there is nothing for you that would be scary. You can watch me do it and you can simply follow along you will learn ALL the basics. I swear I wish something like this was out there when I started learning because everyone else explains things in such a complicated way and makes it so boring! I honestly think programming is based upon exploration and creativity rather than some mathematical/logical genius frame of mind! I spent a lot of hard work in making this so I hope you guys enjoy and learn something out of it while having fun! This is targeted towards beginners, for developers looking to learn python, or for individuals looking for a refresher on basics in computer programming!!

============================= CHANNEL INFO ============================

Enroll for coding exercises, projects, tutorials, and courses...

Clever Programmer
Snapchat ► Rafeh1
Рекомендации по теме
Комментарии
Автор

Can you explain how line 34 at 14:03 works? I can see that it goes down to the line that "guess_row" is valued at, and moves horizontally to "guess_col", but I don't exactly see why it does that. I would think that it would simply put 2 X's in the board, one at the integer for each, but how does it know to go where the two values meet?

Robodav
Автор

I've got a long way to go to get up to date on your tutorial lol. But I'm enjoying the journey! Keep the quality vids going (:

ambermeows
Автор

I tried this one and it worked but I want to hear you all's opinion:

if guess_row < range(5) and guess_col < range(5):

Any problems that would result out of this?

BrianGlaze
Автор

I like that you are funny! Thanks for your videos

daniellaarriola
Автор

hey! at 27:06 thats me for two days everytime i get on codecademy to figure it out how to write this code. i try to do all possiblities before continuing tutorial, but honestly i made it work, than the stupid elif statement was screwing with me til i finally got fed up and hit only problem was that i didnt put parentheses on my statement.

T.Felder
Автор

at the end i was like screaming "YOU FORGOT THE PERIOD" and you didnt notice

footballfan
Автор

Rafeh great job but I believe that the code would break if you go out of range. Please test it to verify.

cambrowne
Автор

Sometimes i think, that I'm too stupid and lazy for coding... I got so far only because of your videos.

splurgeolla
Автор

Rafeh, Please thoroughly test the code for Bad aim. I believe that it would break when you go out of range. Cameron Browne

cambrowne
Автор

I keep getting an error that looks like this:
Traceback (most recent call last):
File "python", line 31, in <module>
IndexError: list index out of range

my code looks like this:




from random import randint

board = []

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

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

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)
guess_row = int(raw_input("Guess Row: "))
guess_col = int(raw_input("Guess Col: "))

print (ship_row)
print (ship_col)

# Write your code below!
if guess_row == ship_row and guess_col == ship_col:
print("Congratulations! You sank my battleship!")
elif board[guess_row][guess_col] == "X":
print ("You guessed that one already.")
if guess_row not in range(5) or guess_col not in range(5):
print("Oops, that's not even in the ocean.")
else:
print("you missed my Battleship!")
board[guess_row][guess_col] = "X"
print_board(board)

anshc
Автор

i keep getting an error 'raw input' not defined

abdulwasiubalogun
Автор

You are a fucking King dude. I would love to hang out with u one day. I feel like I would instantly become smarter :)

hshah
Автор

Funny when you laugh at your own jokes ><

ksp
Автор

from random import randint

board = []

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

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

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)

guess_row = int(input("Guess Row: "))
guess_col = int(input("Guess Col: "))

# Write your code below!
if guess_row == ship_row and guess_col == ship_col:
print ("Congratulations! You sank my battleship!")

elif guess_row not in range(5) or guess_col not in range(5):
print ("Oops, that's not even in the ocean")
else:
print ("You missed my battleship!")
board[guess_row][guess_col] = "X"
print_board(board)

cornholio
join shbcf.ru