22 lines
674 B
Python
22 lines
674 B
Python
# BATTLESHIPS - Grade 7 Python Game
|
|
# Lesson 1: Find the hidden ship!
|
|
|
|
import random
|
|
|
|
# Step 1: Create a secret ship location (row 0-4, col 0-4)
|
|
ship_row = random.randint(0, 4)
|
|
ship_col = random.randint(0, 4)
|
|
|
|
# Step 2: Ask the player for a guess (we'll improve this later!)
|
|
print("Guess the ship location!")
|
|
guess_row = int(input("Row (0-4): "))
|
|
guess_col = int(input("Col (0-4): "))
|
|
|
|
# Step 3: Check if they hit the ship
|
|
if guess_row == ship_row and guess_col == ship_col:
|
|
print("🎯 HIT! You sank the ship!")
|
|
else:
|
|
print("💦 MISS! Try again.")
|
|
|
|
# Step 4: (Optional) Show where the ship really was
|
|
print("The ship was at row", ship_row, "and col", ship_col) |