Public Group active 3 weeks, 1 day ago

PUG – Python User’s Group

Python User’ Group (or PUG for short) is an open and informal collaborative space for experimentation and exploration with the Python programming language. It is an opportunity for those interested in Python to work together virtually and find support. Whether you are looking for advice or assistance with new or current projects, looking to discuss and learn new skills using Python tools, or to join us to play around with our collection of sample datasets, PUG is your place!

PUG is open to people of all skill levels, disciplines, and backgrounds. Complete beginners to Python will find a place here. Come, and let’s learn together.

Join PUG Slack here:

PUG is cosponsored by the MA in Digital Humanities / MS in Data Analytics and Visualization programs and the Mina Rees Library.

To learn more, visit


Speeding Ticket Calculator in Python

  • Hi,

    I’m posting here to see if anyone can help me with the following problem:

    “You are driving a little too fast, and a police officer stops you. Write code to compute the result, encoded as an int value: 0=no ticket, 1=small ticket, 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday — on that day, your speed can be 5 higher in all cases. Define a function “caught_speeding(speed, is_birthday)” that returns the value of your ticket.”

    I know how to assign speed scales but not sure how to add the birthday function.

    Thank you!






Viewing 1 replies (of 1 total)
  • One of the possible options could be this – one of the arguments of the function “caught_speeding” is “is_birthday” – so in the input, for example, you can ask whether it is someone’s birthday, and if they reply ‘Yes’, then you add 5 to the speed and calculate the results, otherwise (else), the calculation is done with the original speed – something like this:

    def caught_speeding(speed,is_birthday):
         if is_birthday == 'Yes':​
            speed_updated = speed + 5​​
            if speed_updated < 60:​
               return 'Zero_Updated'​
            if speed_updated > 60:​
               return 'One_Updated'​
            if speed < 60:​
               return 'Zero'​
            if speed > 60:​
               return 'One'

    Calling the function with whether the birthday is ‘yes’:
    caught_speeding(50, 'Yes')
    returns ‘Zero_Updated’

    And calling the function with whether the birthday is ‘no’ or any other string:
    caught_speeding(50, 'No')
    returns ‘Zero’

    Hope this is helpful and please let know if anything else could be helpful –

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.