Guest User

Untitled

a guest
Nov 18th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. # U07_Ex06_speeding_ticket.py
  2. #
  3. # Author: David Hanft
  4. # Course: Coding for OOP
  5. # Section: A3
  6. # Date: 13 Nov 2017
  7. # IDE: Python 3.6.2
  8. #
  9. # Assignment Info
  10. # Exercise: 6
  11. # Source: Python Programming
  12. # Chapter: 7
  13. #
  14. # Program Description
  15. # This program calculates speeding ticket in Podunksville, which is $50 puts $5
  16. # for each mph over the limit, plus a $200 penalty for any speed over 90 mph
  17. # Algorithm (pseudocode)
  18. # def main():
  19. # input for speed limit
  20. # input for clocked speed
  21. # run calc()
  22. # def calc(limit, speed):
  23. # if speed > limit:
  24. # illegal = True
  25. # else:
  26. # illegal = False
  27. # fine = 'No fine'
  28. # if illegal == True and <= 90:
  29. # fine = (speed-limit)(5)+50
  30. # else:
  31. # fine = (speed-limit)(5)+50+200
  32. # return fine
  33. def main():
  34. limit = int(input('Speed Limit: '))
  35. speed = int(input('Clocked Speed: '))
  36. calc(speed, limit)
  37. fine = calc(speed, limit)
  38. # Checking the speed is actually over the limit
  39. if fine == 0:
  40. print('No fine.')
  41. else:
  42. print('Fine: $',fine, sep='')
  43. def calc(speed, limit):
  44. # Series of if statements to decide if the limit is illegal or not, and applying
  45. # the appropriate equation for the fine
  46. fine=0
  47. if speed > limit:
  48. illegal=True
  49. else:
  50. illegal=False
  51. if illegal is True:
  52. fine = (speed-limit)*5+50
  53. if speed > 90:
  54. fine+=200
  55. return int(fine)
  56. if __name__ == '__main__':
  57. main()
Add Comment
Please, Sign In to add comment