Guest User

Untitled

a guest
Jan 27th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. Code for method frame_score:-
  2.  
  3. # Function frame_score
  4. def frame_score(the_frame, bonus1, bonus2):
  5. if the_frame[0]==10:
  6. return 10+bonus1+bonus2
  7. elif the_frame[0]+the_frame[1]==10:
  8. return 10+bonus1
  9. elif the_frame[0]+the_frame[1]<10:
  10. return the_frame[0]+the_frame[1]
  11.  
  12.  
  13. Code for bowling.py
  14.  
  15.  
  16. from framescore import frame_score
  17. from framescore import read_ragged_array
  18.  
  19. filename = input("Enter file name: ")
  20. frames = read_ragged_array(filename)
  21. score = 0
  22. bonus1 = 0
  23. bonus2 = 0
  24. for i in range(1, 11):
  25. if frames[i][0]==10 and frames[i+1][0]==10:
  26. bonus1 = 10
  27. bonus2 = frames[i+2][0]
  28. elif frames[i][0]==10 and frames[i+1][0]<10:
  29. bonus1 = frames[i+1][0]
  30. bonus2 = frames[i+1][1]
  31. elif frames[i][0]+frames[i][1]==10:
  32. bonus1 = frames[i+1][0]
  33. bonus2 = 0
  34. else:
  35. bonus1 = 0
  36. bonus2 = 0
  37. score += frame_score(frames[i], bonus1, bonus2)
  38. print(score)
  39.  
  40. 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.
  41.  
  42. See the below image for well indentated code.
Advertisement
Add Comment
Please, Sign In to add comment