100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Procedural Programming Assignment 3 $9.13   Add to cart

Essay

Procedural Programming Assignment 3

 16 views  0 purchase
  • Course
  • Institution

The document contains all criteria for assignment 3: P2, P4, P5, P6, M2, M3, M4, D2. I received full marks for this assignment.

Preview 2 out of 27  pages

  • July 12, 2022
  • 27
  • 2018/2019
  • Essay
  • Unknown
  • A
avatar-seller
...nment 3\BattleshipLove\BattleshipLove\BattleshipLove.py 1
#­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
Import­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
from pprint import pprint as pp
import random
import time
import sys

#­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
Variable­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
turns = 0
Answer = "NaN"
Rows = 7
Columns = 7

#­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
Welcome­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
print("Welcome to battleship!")
print("gridsize = 7 x 7")
# This part of the code will simply build the grid in a 7x7 format

#­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
CreateGrid­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
# This is an example of a function as it returns the computers grid
# This uses parameters of rows and columns to create the grid of the correct size
def create_gridComputer(Rows, Columns):
#Creates the 2D Data Grid
gridComputer = []
for row in range(Rows): # This is a form of iteration
row = []
for col in range(Columns):
row.append(' ')
gridComputer.append(row)
return gridComputer

gridComputer = create_gridComputer(Rows,Columns)

# This is another example of a function as its returning the players grid
def create_gridPlayer(Rows, Columns):
#Creates the 2D Data Grid
gridPlayer = []
for row in range(Rows):
row = []
for col in range(Columns):
row.append(' ')
gridPlayer.append(row)
return gridPlayer

gridPlayer = create_gridPlayer(Rows,Columns)


#­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
ProcedureToDisplayGrid­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
def display_gridComputer(gridComputer, Columns):
#Prints the labels for the grid
column_names = 'abcdefghijklmnopqrstuvwxyz'[:Columns]
print(' | ' + ' | '.join(column_names.upper()) + ' |')

, ...nment 3\BattleshipLove\BattleshipLove\BattleshipLove.py 2
for number, row in enumerate(gridComputer):
print(number + 1, '| ' + ' | '.join(row) + ' |')

gridComputer = create_gridComputer(Rows, Columns)
display_gridComputer(gridComputer, Columns)

def display_gridPlayer(gridPlayer, Columns):
#Prints the labels for the grid
column_names = 'abcdefghijklmnopqrstuvwxyz'[:Columns]
print(' | ' + ' | '.join(column_names.upper()) + ' |')
for number, row in enumerate(gridPlayer):
print(number + 1, '| ' + ' | '.join(row) + ' |')

gridPlayer = create_gridPlayer(Rows, Columns)
display_gridPlayer(gridPlayer, Columns)


#­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
CompPickShip1­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
def random_row1(gridComputer):
# Function, Makes a random row integer, computer picks random row
return random.randint(1,len(gridComputer))

def random_col1(gridComputer):
# Function, Makes a random column integer, computer picks random column
return random.randint(1,len(gridComputer[0]))


#­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
CompPickShip2­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
def random_row2(gridComputer):
#Makes a random row integer, computer picks random row
return random.randint(1,len(gridComputer))

def random_col2(gridComputer):
#Makes a random column integer, computer picks random column
return random.randint(1,len(gridComputer[0]))


#­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
CompPickShip3­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
def random_row3(gridComputer):
#Makes a random row integer, computer picks random row
return random.randint(1,len(gridComputer))

def random_col3(gridComputer):
#Makes a random column integer, computer picks random column
return random.randint(1,len(gridComputer[0]))


#­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
PlayerPickShip1­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
def playerpick_row1(gridPlayer):
#Makes a random row integer, player picks random row
playerpickrow1 = int(input("Pick your First Row"))
return playerpickrow1

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller ItsKenzie. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $9.13. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

64438 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$9.13
  • (0)
  Add to cart