βŒ›οΈ Quiz 4 - Understanding Data Types#

This quiz evaluates your mastery of data types and indexing arrays.

Instructions#

You will click on the following link to start your quiz. Do not start the quiz before your lab section. We have checks in place to ensure that you do not start the quiz early. If you do, you will receive a 0 on the quiz. Furthermore, it could be considered an academic integrity violation.

CLICK HERE TO START YOUR QUIZ IN LAB

Entering Your Information for Credit#

To receive credit for assignments it is important we can identify your work from others. To do this we will ask you to enter your information in the following code block.

Before you begin#

Run the block of code at the top of the notebook that imports and sets up the autograder. This will allow you to check your work.

# Please provide your first name, last name, Drexel ID, and Drexel email. Make sure these are provided as strings. "STRINGS ARE TEXT ENCLOSED IN QUOTATION MARKS."

# In the assignments you will see sections of code that you need to fill in that are marked with ... (three dots). Replace the ... with your code.
first_name = ...
last_name = ...
drexel_id = ...
drexel_email = ...

Question 1: Chemical Reaction

A first-order chemical reaction of substance \(A\) produces \(B\). The reaction can be represented as:

\[ aA \rightarrow bB \]

where:

  • \( a \) is the stoichiometric coefficient of the reactant \( A \).

  • \( b \) is the stoichiometric coefficient of the product \( B \).

  • \( A_0 \) is the initial concentration of \( A \).

The amount of product \( B \) formed is directly related to the amount of reactant \( A \) consumed, based on their stoichiometric relationship.

\[ B = A \frac{b}{a} \]

Complete the function to calculates the amount of \( B \) formed from the initial amount of \( A \).

In this example, for every 2 moles of A, 3 moles of B are produced. The function calculate_product_amount calculates the amount of B formed from the given initial concentration of A. This calculation assumes that all of A is consumed in the reaction.

Write code that

  • asserts that all of the initial \(A\) reacts in a variable reacted_A.

  • applies stoichiometry to determine the amount of \(B\) produced following the equation above. Save to a variable product_B.

  • generates a brief report of the B produced for a given initial amount of A. Save to a variable report.

"The amount of product B formed: ____ mol B."

The value should be reported with two digits after the decimal point. You should use a string formatting expression to do this.

Write python code to do the following:

Your code replaces the prompt: ...

# This line creates a function called caffeine_levels which has 2 arguments: amt and hours
def calculate_product_amount():
    """
    Calculate the amount of product B formed in the reaction aA -> bB.

    Args:
    a (int): Stoichiometric coefficient of A.
    b (int): Stoichiometric coefficient of B.
    A0 (float): Initial concentration of A in moles.

    Returns:
    float: Amount of product B formed in moles.
    """
    # Stoichiometric coefficients
    a = 2  # stoichiometric coefficient of A
    b = 3  # stoichiometric coefficient of B

    # initial concentration
    A0 = 4.0  # mol A

    ...

    return a, b, reacted_A, product_B, report


a, b, reacted, product, report = calculate_product_amount()

Question 2: Select portions of sensor data

Engineers often use sensors that provide a reading across a surface. For instance, a materials scientist may look at a quantity across a surface, or environmental engineers may be interested in rainfall across a region.

You will select different poritons of a randomly-populated, two-dimensional array of length 5 in each dimension.

Write python code to do the following:

  • assign specific_sensor_reading the reading of the sensor at third row and fourth column

  • assign row_sensors the sensor readings in the fourth row

  • assign column_sensors the sensor readings in the third column

  • assign sub_grid the sensor readings in a 2 rows by 3 columns sub-grid from top-left corner

Your code replaces the prompt: ...

import numpy as np

# This line creates a function called parse_phone_number which has 1 argument: S
def question_2(seed=None):
    # Set the seed for reproducibility
    np.random.seed(seed)

    # Generate a 5x5 grid of sensor readings
    sensor_grid = np.random.rand(5, 5) * 100

    ...
    # this line outputs the parsed number from the function
    return specific_sensor_reading, row_sensors, column_sensors, sub_grid

Submitting Your Assignment#

To submit your assignment please use the following link the assignment on GitHub classroom.

Use this link add link to navigate to the assignment on GitHub classroom.

If you need further instructions on submitting your assignment please look at Lab 1.

Viewing your score#

Each .ipynb file you have uploaded will have a file with the name of your file + Grade_Report.md. You can view this file by clicking on the file name. This will show you the results of the autograder.

We have both public and hidden tests. You will be able to see the score of both tests, but not the specific details of why the test passed or failed.

Note

In python and particularly jupyter notebooks it is common that during testing you run cells in a different order, or run cells and modify them. This can cause there to be local variables needed for your solution that would not be recreated on running your code again from scratch. Your assignment will be graded based on running your code from scratch. This means before you submit your assignment you should restart the kernel and run all cells. You can do this by clicking Kernel and selecting Restart and Run All. If you code does not run as expected after restarting the kernel and running all cells it means you have an error in your code.

Fin#