Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code for method frame_score:-
- # Function frame_score
- def frame_score(the_frame, bonus1, bonus2):
- if the_frame[0]==10:
- return 10+bonus1+bonus2
- elif the_frame[0]+the_frame[1]==10:
- return 10+bonus1
- elif the_frame[0]+the_frame[1]<10:
- return the_frame[0]+the_frame[1]
- Code for bowling.py
- from framescore import frame_score
- from framescore import read_ragged_array
- filename = input("Enter file name: ")
- frames = read_ragged_array(filename)
- score = 0
- bonus1 = 0
- bonus2 = 0
- for i in range(1, 11):
- if frames[i][0]==10 and frames[i+1][0]==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][0]
- bonus2 = 0
- else:
- bonus1 = 0
- bonus2 = 0
- score += frame_score(frames[i], bonus1, bonus2)
- print(score)
- As you have not given all the files given in description so i have used the mentioned functions directly. To run the codes, make the suggested changes in read_ragged_array given in point (5) and use the code which i have given. I have used function read_ragged_function directly and have supplied the filename which is being read. If the method takes the input in different way then just make the change as per given code.
- See the below image for well indentated code.
Advertisement
Add Comment
Please, Sign In to add comment