1 / 79

Python Programming, 3/e

Python Programming: An Introduction to Computer Science. Chapter 9 Simulation and Design. Python Programming, 3/e. 1. Objectives. Python Programming, 3/e. 1. Objectives. Python Programming, 3/e. 1. Simulating Racquetball. Python Programming, 3/e. 1. A Simulation Problem.

lrhodes
Download Presentation

Python Programming, 3/e

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Python Programming:An Introduction toComputer Science Chapter 9Simulation and Design Python Programming, 3/e 1

  2. Objectives Python Programming, 3/e 1

  3. Objectives Python Programming, 3/e 1

  4. Simulating Racquetball Python Programming, 3/e 1

  5. A Simulation Problem Python Programming, 3/e 1

  6. Analysis and Specification Python Programming, 3/e 1

  7. Analysis and Specification Python Programming, 3/e 1

  8. Analysis and Specification Python Programming, 3/e 1

  9. Analysis and Specification Python Programming, 3/e 1

  10. Analysis and Specification Python Programming, 3/e 1

  11. Analysis and Specification Python Programming, 3/e 1

  12. PseudoRandom Numbers Python Programming, 3/e 1

  13. PseudoRandom Numbers Python Programming, 3/e 1

  14. PseudoRandom Numbers Python Programming, 3/e 1

  15. PseudoRandom Numbers Python Programming, 3/e 1

  16. PseudoRandom Numbers Python Programming, 3/e 1

  17. PseudoRandom Numbers Python Programming, 3/e 1

  18. PseudoRandom Numbers >>> from random import randrange >>> randrange(1,6) 5 >>> randrange(1,6) 3 >>> randrange(1,6) 2 >>> randrange(1,6) 5 >>> randrange(1,6) 5 >>> randrange(1,6) 5 >>> randrange(1,6) 4 Python Programming, 3/e 1

  19. PseudoRandom Numbers Python Programming, 3/e 1

  20. PseudoRandom Numbers Python Programming, 3/e 1

  21. PseudoRandom Numbers >>> from random import random >>> random() 0.79432800912898816 >>> random() 0.00049858619405451776 >>> random() 0.1341231400816878 >>> random() 0.98724554535361653 >>> random() 0.21429424175032197 >>> random() 0.23903583712127141 >>> random() 0.72918328843408919 Python Programming, 3/e 1

  22. PseudoRandom Numbers Python Programming, 3/e 1

  23. PseudoRandom Numbers Python Programming, 3/e 1

  24. PseudoRandom Numbers Python Programming, 3/e 1

  25. Top-Down Design Python Programming, 3/e 1

  26. Top-Level Design Python Programming, 3/e 1

  27. Top-Level Design Python Programming, 3/e 1

  28. Top-Level Design Python Programming, 3/e 1

  29. Top-Level Design Python Programming, 3/e 1

  30. Top-Level Design Python Programming, 3/e 1

  31. Top-Level Design Python Programming, 3/e 1

  32. Top-Level Design Python Programming, 3/e 1

  33. Top-Level Design Python Programming, 3/e 1

  34. Separation of Concerns Python Programming, 3/e 1

  35. Separation of Concerns Python Programming, 3/e 1

  36. Separation of Concerns Python Programming, 3/e 1

  37. Separation of Concerns Python Programming, 3/e 1

  38. Separation of Concerns Python Programming, 3/e 1

  39. Second-Level Design Python Programming, 3/e 1

  40. Second-Level Design Python Programming, 3/e 1

  41. Second-Level Design Python Programming, 3/e 1

  42. Designing simNGames Python Programming, 3/e 1

  43. Designing simNGames initialize winsA and winsB to 0loop n times simulate a game if playerA wins add one to winsA else add one to winsB Python Programming, 3/e 1

  44. Designing simNGames Python Programming, 3/e 1

  45. Designing simNGames Python Programming, 3/e 1

  46. Designing simNGames Python Programming, 3/e 1

  47. Designing simNGames def simNGames(n, probA, probB): # Simulates n games of racquetball between players A and B # RETURNS number of wins for A, number of wins for B winsA = winsB = 0 for i in range(n): scoreA, scoreB = simOneGame(probA, probB) if scoreA > scoreB: winsA = winsA + 1 else: winsB = winsB + 1 return winsA, winsB Python Programming, 3/e 1

  48. Designing simNGames Python Programming, 3/e 1

  49. Third-Level Design Python Programming, 3/e 1

  50. Third-Level Design Python Programming, 3/e 1

More Related