Dec 04, 2025 | 385 words | 4 min read
7.3.2. Task 2#
Learning Objectives#
Create and execute simple scripts comprised of basic Python concepts; Output data from a script to the screen in Python; Apply this course’s programming standards in development of Python scripts; Modularize and comment code in Python for readability and reusability.
Task Instructions#
You may recall from your high school physics class that a capacitor is an electrical component that stores energy in an electric field. Capacitors are commonly used in electronic circuits to store and release energy, filter signals, and stabilize voltage levels. The value of a capacitor’s capacitance is given by \(C\) (with unit Farads \([\farad]\)).
In circuits with many components, we can calculate an equivalent capacitance for the entire circuit using the individual capacitances of each component. Knowing this equivalent capacitance can make calculating other properties of the circuit much easier.
We frequently encouter two electrical circuit topologies: series and parallel. For each type, one can calculate a total capacitance for the entire circuit, but the two are calculated differently. The total capacitance for series capacitors is calculated as shown in (7.4), while that for parallel capacitors is shown in (7.5).
Create a program to calculate the total capacitance of two capacitors arranged in series and in parallel. The program should output the results for both series AND parallel calculations. The value of the first capacitor’s capacitance should be an input from the user, while the second capacitor’s capacitance should be hardcoded as \(\qty{e^3\sqrt[]{5}}{\mu\farad}\) where \(e\) is Euler’s number .
A flowchart illustrating your program’s logic should be created and saved in a PDF file
named py1_ind_2_username.pdf. Start
your Python script from ENGR133_Python_Template.py and save it as
py1_ind_2_username.py. Use the sample
output section below to verify that your program outputs correct values.
Sample Output#
Use the values in Table 7.11 below to test your program.
Case |
Capacitor 1 |
|---|---|
1 |
10 |
2 |
30 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 py1_ind_2_username.py Input the capacitance of the first capacitor [μF]: 10 Type First Second Total Series 10.0 μF 44.9 μF 8.2 μF Parallel 10.0 μF 44.9 μF 54.9 μF
Case 2 Sample Output
$ python3 py1_ind_2_username.py Input the capacitance of the first capacitor [μF]: 30 Type First Second Total Series 30.0 μF 44.9 μF 18.0 μF Parallel 30.0 μF 44.9 μF 74.9 μF
Hints
Use f-strings to format your output.
Line your output values up by setting a width in your f-string. For example,
f"{value:10.2f}"will format the value to have a width of \(10\) characters and \(2\) decimal places.
Entering
\u03bcin a string will produce the \(\mu\) symbol.
Deliverables |
Description |
|---|---|
py1_ind_2_username.pdf |
Flowchart(s) for this task. |
py1_ind_2_username.py |
Your completed Python code. |