Question: PYTHON ASSIGNMENT A bowling frame is represented by a Fixnum array of length 2 if the frame is a spare or an open frame, for

PYTHON ASSIGNMENT

A bowling frame is represented by a Fixnum array of length 2 if the frame is a spare or an open frame, for example [6, 4] or [5, 3]. A bowling frame is represented by an array of length 1 if the frame is a strike: [10].

A bowling game is represented by a ragged array containing its frames, including the bonus balls if the last frame is a strike or a spare. For example, here are the representations of Games 1, 2, and 3:

Game Number File Name Ragged Array
Game 1 game1.txt [["Frame0"], [8,0],[7,2],[6,0],[6,2], [0,8],[6,1],[9,0],[8,0],[8,1],[5,2]]
Game 2 game2.txt [["Frame0"], [8,1],[7,3],[5,3],[0,10], [7,3],[9,1],[9,0],[8,2],[8,1], [5,5],[8]]
Game 3 game3.txt [["Frame0"], [8,1],[10],[6,4],[8,1], [9,1], [10],[10],[10], [9,1], [10],[10],[8]]

(1) Write a method named frame_score in the file framescore.py with this header:

def frame_score(the_frame, bonus1, bonus2) 

(2) Use an if..else statement with three cases: Case 1: the_frame[0] == 10 (frame is a strike) Action: return 10 + bonus1 + bonus2 Case 2: the_frame[0] + the_frame[1] == 10 (frame is a spare) Action: return 10 + bonus1 Case 3: the_frame[0] + the_frame[1] < 10 (frame is an open frame) Action: return the_frame[0] + the_frame[1]Use this unit test script to test your frame_score method:

# Filename: testframescore.py import unittest from framescore import frame_score class TestFrameScore(unittest.TestCase): def test_1(self): self.assertEqual(frame_score([10], 10, 7), 27) def test_2(self): self.assertEqual(frame_score([7, 3], 9, 0), 19) def test_3(self): self.assertEqual(frame_score([7, 1], 0, 0), 8) if __name__ == '__main__': unittest.main() 

(3) Write a main script in the file bowling.py that computes the bowling score from the scores for a game in an input file:

(4) Prompt the user for the name of the input file, for example, game1.txt, game2.txt, or game3.txt.

(5) Use the read_ragged_array method from the RaggedArray Example to read the game scores from the input file into a ragged array (see the table above). Make these changes to the read_ragged_array method before using it:

(6) Change the delimiter in the split method to be " " instead of ",".

(7) Store the values in the ragged array as int values instead of float.

(8) Store the frames in an array named frames. Also, instead of initializing the frames array to [ ], initialize it to [["Frame0"]] so that the first actual bowling frame inframes is at index 1. ["Frame0"] is a placeholder at index 0.

(9) Loop over each frame in the frames array to compute the sum of all the return values of theframe_score method calls.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!