Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using python do the following : Given a grid - suppose for example it has 4 vertical lines of length 400 and 3 horizontal lines

Using python do the following :

Given a grid - suppose for example it has 4 vertical lines of length 400 and 3 horizontal lines of length 500 - write a function to determine which column a particular x value lies in, and a separate function to determine which row a particular y value lies in. In the example grid mentioned above, there would be 5 columns (determined by the number of vertical lines) and 4 rows (determined by the number of horizontal lines); a particular column would be a number between 1 and 5; a particular row would be a number between 1 and 4. The cell in the lower left corner would be in column 1 and row 1. The cell in the top right would be in column 5 and row 4.Use the test harness below and add more test cases. Use the function names and parameter lists provided. Some of the parameters are not actually used but the lists are the same for continuity. These functions will eventually be used to determine which cell the user has clicked in.

Code that was given:

import sys def column(nv, lv, nh, lh, cx, cy, x, y): ''' Return column of the grid with nv vertical lines and horizontal lines of length lh, centred at (cx,cy), that contains (x, y). ''' def row(nv, lv, nh, lh, cx, cy, x, y): ''' Return row number of the grid with nh horizontal lines and vertical lines of length lv, centred at (cx,cy), that contains (x, y). ''' # # ============================================================================ # Test suite - do not change anything between this and the next marker comment # lines def print_test(did_pass): ''' print result of testing function ''' linenum = sys._getframe(1).f_lineno if did_pass: print('Test at line '+str(linenum)+' ok.') else: print('Test at line '+str(linenum)+' FAILED.') def test_suite(): ''' test functions ''' # # # For function column the parameters nh, lv, cy and y are not used; and # for function row the parameters nv, lh, cx and x are not used - but # we keep the parameter lists the same for consistency. # Remember parameters are: # (nv,lv, nh,lh, cx, cy,x, y) # with grid centered at (0,0) horizontal length 300 and 2 vertical lines # the cell sizes are 100 starting at -150 ... print_test(column(2, 300, 2, 300, 0, 0, -120, 120) == 1) print_test(column(2, 300, 2, 300, 0, 0, -50, 120) == 1) # on boundary print_test(column(2, 300, 2, 300, 0, 0, 40, 20) == 2) print_test(column(2, 300, 2, 300, 0, 0, 50, 20) == 2) print_test(column(2, 300, 2, 300, 0, 0, 80, 20) == 3) print_test(column(2, 300, 2, 300, 0, 0, 150, 20) == 3) # with grid centered at (150,0) horizontal length 300 and 2 vertical lines # the cell sizes are 100 starting at 0 ... print_test(column(2, 300, 2, 300, 150, 0, 0, 20) == 1) # on boundary print_test(column(2, 300, 2, 300, 150, 0, 100, 20) == 1) # on boundary print_test(column(2, 300, 2, 300, 150, 0, 170, 20) == 2) print_test(column(2, 300, 2, 300, 150, 0, 200, 20) == 2) # on boundary # with grid centered at (-150,0) horizontal length 300 and 2 vertical lines # the cell sizes are 100 starting at -300 ... print_test(column(2, 300, 2, 300, -150, 0, -300, 20) == 1) # on boundary print_test(column(2, 300, 2, 300, -150, 0, -120, 20) == 2) print_test(column(2, 300, 2, 300, -150, 0, -100, -120) == 2) # on boundary print_test(column(2, 300, 2, 300, -150, 0, -40, -120) == 3) print_test(column(2, 300, 2, 300, -150, 0, 0, -120) == 3) # on boundary # Add more calls to properly test the functions - e.g. to further test the # column function change the number of vertical lines and the horizontal # line length. # Add similar tests for the row function. # ========================================================================= # # Main program # test_suite() 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions