๐Ÿฅจ Philly Pretzel Challenge!

# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment

responses = initialize_assignment("13_Philly_Python_Challenge", "week_1", "lecture", assignment_points = 5.0, assignment_tag = 'week1-lecture')

# Initialize Otter
import otter
grader = otter.Notebook("13_Philly_Python_Challenge.ipynb")

๐Ÿฅจ Philly Pretzel Challenge!#

Philly Pretzel Challenge

The Problem#

In Philadelphia, soft pretzels are a beloved snack. Imagine a group of friends buying a box of pretzels to share:

  • There are 23 pretzels in the box.

  • There are 5 friends in the group.

Write a program to calculate:

  1. How many pretzels each friend gets (integer division).

  2. How many pretzels are left over (modulus operator).

Detailed Instructions:

  1. Define the Total Number of Pretzels:

    • Create a variable named pretzels and assign it the value 23.

    • This represents the total number of soft pretzels available in the box.

  2. Define the Number of Friends:

    • Create a variable named friends and assign it the value 5.

    • This represents the number of friends sharing the pretzels.

  3. Calculate How Many Pretzels Each Friend Gets:

    • Use integer division (//) to divide pretzels by friends.

    • Integer division gives the whole number of pretzels each friend can get without considering leftovers.

    • Store the result in a variable named pretzels_per_friend.

  4. Calculate the Leftover Pretzels:

    • Use the modulus operator (%) to divide pretzels by friends and determine the remainder.

    • The remainder represents the number of pretzels left after evenly distributing them among the friends.

    • Store the result in a variable named leftover_pretzels.

  5. Print the Results:

    • Use the print() function to display how many pretzels each friend gets and how many are left over.

    • Use f-strings to include the calculated values in the output.

    print(f'Each friend gets {pretzels_per_friend} pretzels.')
    print(f'There are {leftover_pretzels} pretzels left over.')
    
    • The output will look like this:

      Each friend gets 4 pretzels.
      There are 3 pretzels left over.
      
def pretzel_calculator():
    # This line of code defines a function
    # You should write your code where the ... is located
    # Do not change code above this line 
    
    # 1. Define the total number of pretzels and friends
    ...

    # 2. Calculate How Many Pretzels Each Friend Gets
    ...

    # 3. Calculate How Many Pretzels Are Left Over
    ...

    # 4. Print the Results
    # Tip: Copy the code from above we provided it for you
    ...

    # Do not change code below this line
    return pretzels_per_friend, leftover_pretzels
grader.check("activity-2-Philly Pretzel Challenge")

๐ŸŽ‰ Well Done!#

Congratulations on completing the Philly Python Challenge! Now go grab a soft pretzel to celebrate! ๐Ÿฅจ

Submitting Assignment#

Please run the following block of code using shift + enter to submit your assignment, you should see your score.

from pykubegrader.submit.submit_assignment import submit_assignment

submit_assignment("week1-lecture", "13_Philly_Python_Challenge")