Rédigé par des étudiants ayant réussi Disponible immédiatement après paiement Lire en ligne ou en PDF Mauvais document ? Échangez-le gratuitement 4,6 TrustPilot
logo-home
Dissertation

Procedural Programming Assignment 3

Note
-
Vendu
-
Pages
27
Grade
A
Publié le
12-07-2022
Écrit en
2018/2019

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

Établissement
Cours

Aperçu du contenu

...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

École, étude et sujet

Niveau d'études
Editeur
Sujet
Cours

Infos sur le Document

Publié le
12 juillet 2022
Nombre de pages
27
Écrit en
2018/2019
Type
DISSERTATION
Professeur(s)
Inconnu
Grade
A

Sujets

€8,90
Accéder à l'intégralité du document:

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Faites connaissance avec le vendeur
Seller avatar
ItsKenzie
5,0
(9)

Document également disponible en groupe

Faites connaissance avec le vendeur

Seller avatar
ItsKenzie University
S'abonner Vous devez être connecté afin de suivre les étudiants ou les cours
Vendu
20
Membre depuis
6 année
Nombre de followers
10
Documents
78
Dernière vente
2 année de cela
IT and Cyber Security Notes For Computing Students

I prepare and sell top quality notes and essays that are concise and easy to understand to fellow computing students. It can be overwhelming when you get your first few projects or assignments, using my notes and essays can help you to better understand the modules and hopefully help you get the grades you want. Thanks for visiting my profile, feedback is always appreciated.

5,0

9 revues

5
9
4
0
3
0
2
0
1
0

Documents populaires

Récemment consulté par vous

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions