lab_fundamentals

Fulfilling Fundamentals

Due: Jan 13, 23:59 PM

Learning Objectives

  • Discuss lab structure and acceptable groupwork policies
  • Review the basics of variable type, conditionals, and loops
  • Review the Jupyter notebook format for autograded assessment

Submission Instructions

Using the Prairielearn workspace, test and save your solution to the following exercises. (You are welcome to download and work on the files locally but they must be re-uploaded or copied over to the workspace for submission).

Assignment Description

This assignment is meant to be a review and assessment of your Python programming skills through a few short exercises. While the details of the assignment (as well as some example input / output for each function) can be found in the notebook itself, here is a brief overview of the tasks:

getTotalTime()

float getTotalTime(str checkin, str checkout)
# INPUT:
# A string (checkin)
# A string (checkout)
# OUTPUT:
# A float storing the number of minutes between checkin and checkout time.

This first exercise tests your knowledge on variables – your input is a precisely formatted pair of strings and your output is a float. Consider what steps you need to go from input to output!

getSmallestEvent()

int getSmallestEvent(int x, int y, int z)
# INPUT:
# An integer (x)
# An integer (y)
# An integer (z)
# OUTPUT:
# An integer that is the smallest even number from the three inputs

This function tests your knowledge of modulo arithmatic as well as conditional statements. That said, there are many ways to solve this problem so have fun with it! Just be sure your approach can handle every case.

electricBill()

float electricBill(int watts)
# INPUT:
# An integer (watts)
# OUTPUT:
# An float that contains the total cost according to billing logic.

This is another exercise in conditionals and is slightly more nuanced in that your code must implement the following rules in order (or you will likely not end up with the correct total). The rules are as follows:

  1. If the total wattage is greater than or equal to 500, each watt costs 10.
  2. If the total wattage is less than 50, each watt costs 4. Otherwise (for any wattage between 50 and 499):
  3. The first 50 watts costs 5 each
  4. The next 50 watts cost 5.5 each
  5. Any remaining watts cost 8 each

Good luck!

oddCountByIncrement()

int geqThan(int start, int stop, int increment)
# INPUT:
# An integer (start)
# An integer (stop)
# A positive integer (increment)
# OUTPUT:
# An integer that is the total count of odd values between start and stop.

This exercise tests your knowledge of the for loop and to a lesser extend your knowledge of the range function. If you are stuck, first try making sure your loop iterates through the numbers it is supposed to. Then add the logic on how to count the odd values.

sumUntilGreater()

int sumUntilGreater(int start, int stop)
# INPUT:
# A non-negative integer (start)
# A non-negative integer (stop)
# OUTPUT:
# An integer that is the first sum of k values (start, start+1, ..., start+k-1) larger than stop

When you cannot immediately determine the number of iterations a loop will take, you likely need to use a while loop. In this exercise you need to add up the sequential numbers from start and stop once your total sum is larger than stop. So for example if my start was 0 and my stop was 15:

0+1+2+3+4+5+6=21 

is the first sum larger than 15. Your solution should still work even if stop is smaller than start. What value should that return?