14,303,493 members
Rate this:
See more:
I need to write an application that computes bowling scores. This is more for clarification and understanding my mistakes because I really want to understand how to complete this task.

```Import the frame_score method from
the file framescore.py

the framescore.py file.
(See the RaggedArray Example)

read inputfile from keyboard, promping user.
Call the read_ragged_array method to create
a ragged array of the data in the input_file like
game1.txt, game2.txt, or game3.txt.
Assign the ragged array to the variable frames.

Initialize score to 0.
For i in the range from 1 to 10 (use range(1, 11))
if frames[i][0] equals 10 and frames[i+1][0] equals 10
assign 10 to bonus1.
assign frames[i+2][0] to bonus2.
elsif frames[i][0] equals 10 and frames[i+1][0] < 10
assign frames[i+1][0] to bonus1.
assign frames[i+1][1] to bonus2.
elsif frames[i][0] + frames[i][1] equals 10
assign frames[i+1][0] to bonus1.
assign zero to bonus2.
else
assign zero to bonus1.
assign zero to bonus2.
end if
# Next line is actual Python statement.
score += framescore(frames[i], bonus1, bonus2)
End loop.

What I have tried:

bowling.py
<pre># import the frame_score method from the file framescore.py
from framescore import frame_score
# import the read_ragged_array method from the framescore.py file.

# read inputfile from keyboard, promping user.
# call the read_ragged_array method to create
# a ragged array of the data in the input_file like
# game1.txt, game2.txt, or game3.txt.
input_file = input("Enter name of input file ('game1.txt, game2.txt, game3.txt'):")

# assign the ragged array to the variable frames.

# Initialize score to 0.
score = [0]

for i in range(1, 11):
if frames[i][0] == 10 and frames[i+1][10] == 10:
bonus1 = 10
bonus2 = frames[i+2][0]
elif frames[i][0] == 10 and frames[i+1][0] < 10:
bonus1 = frames[i+1][0]
bonus2 = frames[i+1][1]
elif frames[i][0] + frames[i][1] == 10:
bonus1 = frames[i+1][1]
bonus2 = 0
else:
bonus1 = 0
bonus2 = 0
# next line is actual Python statement.
while True:
score += frame_score(frames[i], bonus1, bonus2)
#End loop.

print(score)```

framescore.py
```def frame_score(the_frame, bonus1, bonus2):
# Case where frame is a strike
if the_frame[0] == 10:
return 10 + bonus1 + bonus2
# Case where frame is a spare
elif the_frame[0] + the_frame[1] == 10:
return 10 + bonus1
# Case where frame is an open frame
else:
return the_frame[0] + the_frame[1]

frames = [["Frame0"]]
f = open(input_file, "r")
while line:
fields = line.split(" ")
row = [ ]
for field in fields:
row.append(int(field.strip( )))
frames.append(row)
return frames

print(frames)

print(frames)

print(frames)

# 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
# in frames is at index 1. ["Frame0"] is a placeholder at index 0.
# Loop over each frame in the frames array to compute the sum of all the return values
# of the frame_score method calls.```
Posted
Richard MacCutchan 30-Jan-19 11:58am

What is the question?