Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # U07_Ex06_speeding_ticket.py
- #
- # Author: David Hanft
- # Course: Coding for OOP
- # Section: A3
- # Date: 13 Nov 2017
- # IDE: Python 3.6.2
- #
- # Assignment Info
- # Exercise: 6
- # Source: Python Programming
- # Chapter: 7
- #
- # Program Description
- # This program calculates speeding ticket in Podunksville, which is $50 puts $5
- # for each mph over the limit, plus a $200 penalty for any speed over 90 mph
- # Algorithm (pseudocode)
- # def main():
- # input for speed limit
- # input for clocked speed
- # run calc()
- # def calc(limit, speed):
- # if speed > limit:
- # illegal = True
- # else:
- # illegal = False
- # fine = 'No fine'
- # if illegal == True and <= 90:
- # fine = (speed-limit)(5)+50
- # else:
- # fine = (speed-limit)(5)+50+200
- # return fine
- def main():
- limit = int(input('Speed Limit: '))
- speed = int(input('Clocked Speed: '))
- calc(speed, limit)
- fine = calc(speed, limit)
- # Checking the speed is actually over the limit
- if fine == 0:
- print('No fine.')
- else:
- print('Fine: $',fine, sep='')
- def calc(speed, limit):
- # Series of if statements to decide if the limit is illegal or not, and applying
- # the appropriate equation for the fine
- fine=0
- if speed > limit:
- illegal=True
- else:
- illegal=False
- if illegal is True:
- fine = (speed-limit)*5+50
- if speed > 90:
- fine+=200
- return int(fine)
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment