Question

can someone indent this code correctly in python programming def count_neighbors(cells,row,col): rows=len(cells) #storing no. of rows...

can someone indent this code correctly in python programming

def count_neighbors(cells,row,col):
rows=len(cells) #storing no. of rows
cols=len(cells[0]) #storing no. of columns
if(row<0 or col<0 or row>rows-1 or col>cols-1): # when row or column is out of range
return -1
count=0
if(row==0 and cells[rows-1][col]==1): #cyclic order
count+=1
if(col==0 and cells[row][cols-1]==1):
count+=1
if(row==rows-1 and cells[0][col]==1):
count+=1
if(col==cols-1 and cells[row][0]==1):
count+=1
if(col>=1 and cells[row][col-1]==1): #left neighbor
count+=1
if (row>=1 and cells[row-1][col]==1): #upper neighbor
count+=1
if(row+1<rows and cells[row+1][col]==1): #down neighbor
count+=1
if(col+1<cols and cells[row][col+1]==1): #right neighbor
count+=1
if(row+1<rows and col+1<cols and cells[row+1][col+1]==1): #diagonal right down
count+=1
if(row+1<rows and col>=1 and cells[row+1][col-1]==1): #diagonal left down
count+=1
if(row>=1 and col+1<cols and cells[row-1][col+1]==1): #diagonal up right
count+=1
if(row>=1 and col>=1 and cells[row-1][col-1]==1): #diagonal left up
count+=1
return count

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1 def count_neighbprs (cells, row, col): rows-len(cells) #storing no. of cols-len (cells [0]) #storing no. if (row<0 or col<0

Add a comment
Know the answer?
Add Answer to:
can someone indent this code correctly in python programming def count_neighbors(cells,row,col): rows=len(cells) #storing no. of rows...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Throughout this script, can you provide helpful comments about how each function works in the script...

    Throughout this script, can you provide helpful comments about how each function works in the script plus it's significance to the alignment process. Also are there any errors in this script or a way to improve this script? Any help would be appreciated. Thank you. THIS IS A PYTHON CODE AND IS IN IT'S FORMAT _ ITS CLEAR! #!/usr/bin/env python # file=input("Please provide fasta file with 2 sequences:") match=float(input('What is the match score?:')) missmatch=float(input('What is the missmatch score?:')) gap=float(input('What is...

  • 1)def toggle_cell(row, column, cells): • Return value: Flip the cell in the column of row from...

    1)def toggle_cell(row, column, cells): • Return value: Flip the cell in the column of row from alive to dead or vice versa. Return True if the toggle was successful, False otherwise. • Assumptions: o cells will be a two-dimensional list with at least one row and one element in that row. o row and column are index values of cells • Notes: o Cells is being edited in place. Note that the return value is a Boolean and not a...

  • python programming: Can you please add comments to describe in detail what the following code does:...

    python programming: Can you please add comments to describe in detail what the following code does: import os,sys,time sl = [] try:    f = open("shopping2.txt","r")    for line in f:        sl.append(line.strip())    f.close() except:    pass def mainScreen():    os.system('cls') # for linux 'clear'    print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")    print(" SHOPPING LIST ")    print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")    print("\n\nYour list contains",len(sl),"items.\n")    print("Please choose from the following options:\n")    print("(a)dd to the list")    print("(d)elete from the list")    print("(v)iew the...

  • To mimic a real-world programming situation, you are given partially-completed code, written by a former employee you...

    To mimic a real-world programming situation, you are given partially-completed code, written by a former employee you have just replaced. Your task is to complete the program he was developing. Fortunately, the former employee's documentation is up-to-date and quite useful Below is the incomplete section of the code, taken from the Python program which is to use Turtle to draw a grid. (In this exercise, a gridis a series of rows, and a rowis a series of boxes or squares.)...

  • Here is my code for minesweeper in python and it has something wrong. Could you please help me to fix it? import tkinter as tk import random class Minesweeper: def __init__(self): self.main = tk.Tk()...

    Here is my code for minesweeper in python and it has something wrong. Could you please help me to fix it? import tkinter as tk import random class Minesweeper: def __init__(self): self.main = tk.Tk() self.main.title("mine sweeper") self.define_widgets() self.mines = random.sample( [(i,j) for i in range(25) for j in range(50) ],self.CustomizeNumberOfMines()) print(self.mines) self.main.mainloop() self.CustomizeNumberOfMines() def define_widgets(self): """ Define a canvas object, populate it with squares and possible texts """ self.canvas = tk.Canvas(self.main, width = 1002, height=502, bg="#f0f0f0") self.canvas.grid(row=0, column=0) self.boxes =...

  • Python code. NO importing modules. you may not use: contains(), index(), sum(),join(), split(). def column_cipher(plaintext): •...

    Python code. NO importing modules. you may not use: contains(), index(), sum(),join(), split(). def column_cipher(plaintext): • Parameter(s): plaintext ----- a string; the message to be encrypted • Return value: A string; the ciphertext after applying the column cipher algorithm • Assumptions: o The standard English alphabet is used: "abcdefghijklmnopqrstuvwxyz" o All strings will be non-empty, entirely lowercase, and only contain valid letters in the alphabet. • How it works: o First, transpose the text into 5 different columns by writing...

  • JAVA JAR HELP...ASAP I have the code that i need for my game Connect 4, but...

    JAVA JAR HELP...ASAP I have the code that i need for my game Connect 4, but i need to create a jar file . the instructions are below. It has to pass some parameters. I am really confused on doing so.l I dont know what to do next. Can someone help me and give detailed descritiopm opn how you ran the jar file in CMD import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Connect4 {               ...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • I only need the "functions" NOT the header file nor the main implementation file JUST the impleme...

    I only need the "functions" NOT the header file nor the main implementation file JUST the implementations for the functions Please help, if its difficult to do the complete program I would appreciate if you could do as much functions as you can especially for the derived class. I am a beginer so I am only using classes and pointers while implementing everything using simple c++ commands thank you in advanced Design and implement two C++ classes to provide matrix...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT