Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C:UsersSteerajat PycharmProjectsuntitled7venvScriptspython.exe C:/Users/Sukhmanjot/Downloads/randomc4 (2).py 25 7 8 Traceback (most recent call last): File C:/Users /Downloads/randomc4 (2).py, line 81, in display_board(bd) File C:/Users/ Downloads/randomc4 (2).py, line

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

C:\Users\Steerajat PycharmProjects\untitled7\venv\Scripts\python.exe "C:/Users/Sukhmanjot/Downloads/randomc4 (2).py" 25 7 8 Traceback (most recent call last): File "C:/Users /Downloads/randomc4 (2).py", line 81, in display_board(bd) File "C:/Users/ Downloads/randomc4 (2).py", line 70, in display_board print(board[j][i], end='') IndexError: list index out of range Process finished with exit code 1 Purpose: To practice testing and debugging, and working with unfamiliar code. Degree of Difficulty: Tricky. This will take some time! You will find a Python script named randomc4.py on the Assignment 3 Moodle page. Its intended purpose is to display on the console a number of random-generated Connect-4"boards." As an example of correct behaviour, here's a correct "board": 6 8 x0.... XOX..... 000.. OXX XXX. . XXO XOX. 0x00 XOXOX000 . . . O OOXXX..X The first line of the output indicates how many boards are being displayed; in this case, there are 2. After that the output tells the height (6) and width (8) of the first board. After that, there are 6 lines of text (the number of lines depends on the indicated height), with one character per board position. There are Xs and Os, and the character" which means it's unoccupied. The script should display several such boards, of various random sizes, and a blank line always separates an example from any board that follows. There is a second board in the above example, with its own height and width, and distribution of tokens. This script was written and tested by an expert Python programmer, and all tests were passed. There are several example files on Moodle that show correct output from a correct version of this script. Because it generates randomized boards, you won't see the exact output that we have shown. In this question, we are not concerned about checking if the board is valid or not. The boards you generate may have one or more sequences of either token; it's random, and doesn't have to be perfectly realistic. The script we provide to you started with the correct script, but then modified by adding bugs into the script, similar in nature to the kinds of bugs that plague first year students, and very much related to the ideas of Chapter 2 of the course readings, and Lab 02. Ouput should be like as example given in pink box # randomly creates Connect 4 boards of different sizes # These random boards are not realistic, and the algorithm is # very naive: # Create an empty board # Choose a random column, and 'drop' a token ('X' or '0') if the column is full, choose another random column # A board is represented as a list of columns. # Because Connect-4 works using "gravity", dropping a token # is implemented by putting the new token at the end of a list. # We're dropping a token "on top" of all the other tokens already # in the column. So the top of the column is the end of the list. import random as rand height = 5 width = 7 def random_filled (height, width): Create a random board with given dimensions. A board is represented as a list of columns. board - [[]] * width # Choose a random number of moves # - at least 8 # - no more than 80% of the board is full plays = rand.randint(8, int(0.8*height*width)) player = 'X' for i in range(plays): valid_col = False while not valid_col: col_choice F rand.randrange(0, width) col = board[col_choice] if len(board(col_choice]) display_board(bd) File "C:/Users/ Downloads/randomc4 (2).py", line 70, in display_board print(board[j][i], end='') IndexError: list index out of range Process finished with exit code 1 Purpose: To practice testing and debugging, and working with unfamiliar code. Degree of Difficulty: Tricky. This will take some time! You will find a Python script named randomc4.py on the Assignment 3 Moodle page. Its intended purpose is to display on the console a number of random-generated Connect-4"boards." As an example of correct behaviour, here's a correct "board": 6 8 x0.... XOX..... 000.. OXX XXX. . XXO XOX. 0x00 XOXOX000 . . . O OOXXX..X The first line of the output indicates how many boards are being displayed; in this case, there are 2. After that the output tells the height (6) and width (8) of the first board. After that, there are 6 lines of text (the number of lines depends on the indicated height), with one character per board position. There are Xs and Os, and the character" which means it's unoccupied. The script should display several such boards, of various random sizes, and a blank line always separates an example from any board that follows. There is a second board in the above example, with its own height and width, and distribution of tokens. This script was written and tested by an expert Python programmer, and all tests were passed. There are several example files on Moodle that show correct output from a correct version of this script. Because it generates randomized boards, you won't see the exact output that we have shown. In this question, we are not concerned about checking if the board is valid or not. The boards you generate may have one or more sequences of either token; it's random, and doesn't have to be perfectly realistic. The script we provide to you started with the correct script, but then modified by adding bugs into the script, similar in nature to the kinds of bugs that plague first year students, and very much related to the ideas of Chapter 2 of the course readings, and Lab 02. Ouput should be like as example given in pink box # randomly creates Connect 4 boards of different sizes # These random boards are not realistic, and the algorithm is # very naive: # Create an empty board # Choose a random column, and 'drop' a token ('X' or '0') if the column is full, choose another random column # A board is represented as a list of columns. # Because Connect-4 works using "gravity", dropping a token # is implemented by putting the new token at the end of a list. # We're dropping a token "on top" of all the other tokens already # in the column. So the top of the column is the end of the list. import random as rand height = 5 width = 7 def random_filled (height, width): Create a random board with given dimensions. A board is represented as a list of columns. board - [[]] * width # Choose a random number of moves # - at least 8 # - no more than 80% of the board is full plays = rand.randint(8, int(0.8*height*width)) player = 'X' for i in range(plays): valid_col = False while not valid_col: col_choice F rand.randrange(0, width) col = board[col_choice] if len(board(col_choice])

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

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

16.3 Describe the purpose of Canadian labour laws.

Answered: 1 week ago

Question

16.6 Outline the three waysto obtain union recognition.

Answered: 1 week ago

Question

16.5 Describe the five steps in a union organizing campaign.

Answered: 1 week ago