\[ \begin{align}\begin{aligned}\newcommand\blank{~\underline{\hspace{1.2cm}}~}\\% Bold symbols (vectors) \newcommand\bs[1]{\mathbf{#1}}\\% Poor man's siunitx \newcommand\unit[1]{\mathrm{#1}} \newcommand\num[1]{#1} \newcommand\qty[2]{#1~\unit{#2}}\\\newcommand\per{/} \newcommand\squared{{}^2} \newcommand\cubed{{}^3} % % Scale \newcommand\milli{\unit{m}} \newcommand\centi{\unit{c}} \newcommand\kilo{\unit{k}} \newcommand\mega{\unit{M}} % % Percent \newcommand\percent{\unit{\%}} % % Angle \newcommand\radian{\unit{rad}} \newcommand\degree{\unit{{}^\circ}} % % Time \newcommand\second{\unit{s}} \newcommand\s{\second} \newcommand\minute{\unit{min}} \newcommand\hour{\unit{h}} % % Distance \newcommand\meter{\unit{m}} \newcommand\m{\meter} \newcommand\inch{\unit{in}} \newcommand\foot{\unit{ft}} % % Force \newcommand\newton{\unit{N}} \newcommand\kip{\unit{kip}} % kilopound in "freedom" units - edit made by Sri % % Mass \newcommand\gram{\unit{g}} \newcommand\g{\gram} \newcommand\kilogram{\unit{kg}} \newcommand\kg{\kilogram} \newcommand\grain{\unit{grain}} \newcommand\ounce{\unit{oz}} % % Temperature \newcommand\kelvin{\unit{K}} \newcommand\K{\kelvin} \newcommand\celsius{\unit{{}^\circ C}} \newcommand\C{\celsius} \newcommand\fahrenheit{\unit{{}^\circ F}} \newcommand\F{\fahrenheit} % % Area \newcommand\sqft{\unit{sq\,\foot}} % square foot % % Volume \newcommand\liter{\unit{L}} \newcommand\gallon{\unit{gal}} % % Frequency \newcommand\hertz{\unit{Hz}} \newcommand\rpm{\unit{rpm}} % % Voltage \newcommand\volt{\unit{V}} \newcommand\V{\volt} \newcommand\millivolt{\milli\volt} \newcommand\mV{\milli\volt} \newcommand\kilovolt{\kilo\volt} \newcommand\kV{\kilo\volt} % % Current \newcommand\ampere{\unit{A}} \newcommand\A{\ampere} \newcommand\milliampereA{\milli\ampere} \newcommand\mA{\milli\ampere} \newcommand\kiloampereA{\kilo\ampere} \newcommand\kA{\kilo\ampere} % % Resistance \newcommand\ohm{\Omega} \newcommand\milliohm{\milli\ohm} \newcommand\kiloohm{\kilo\ohm} % correct SI spelling \newcommand\kilohm{\kilo\ohm} % "American" spelling used in siunitx \newcommand\megaohm{\mega\ohm} % correct SI spelling \newcommand\megohm{\mega\ohm} % "American" spelling used in siunitx % % Inductance \newcommand\henry{\unit{H}} \newcommand\H{\henry} \newcommand\millihenry{\milli\henry} \newcommand\mH{\milli\henry} % % Power \newcommand\watt{\unit{W}} \newcommand\W{\watt} \newcommand\milliwatt{\milli\watt} \newcommand\mW{\milli\watt} \newcommand\kilowatt{\kilo\watt} \newcommand\kW{\kilo\watt} % % Energy \newcommand\joule{\unit{J}} \newcommand\J{\joule} % % Composite units % % Torque \newcommand\ozin{\unit{\ounce}\,\unit{in}} \newcommand\newtonmeter{\unit{\newton\,\meter}} % % Pressure \newcommand\psf{\unit{psf}} % pounds per square foot \newcommand\pcf{\unit{pcf}} % pounds per cubic foot \newcommand\pascal{\unit{Pa}} \newcommand\Pa{\pascal} \newcommand\ksi{\unit{ksi}} % kilopound per square inch \newcommand\bar{\unit{bar}} \end{aligned}\end{align} \]

Oct 24, 2024 | 376 words | 4 min read

5.3.1. Task 1#

Learning Objectives#

Create and execute simple scripts comprised of basic Python concepts; Apply course code standard in development of Python scripts; Modularize and comment code in Python for readability and reusability.

Task Instructions#

In this task, you will be doing calculations using both Python and MS Excel. By performing the calculations with both tools, you will gain insight into the differences in syntax between the two

Part A#

  1. Open the MS Word template: py1_ind_1_username.docx

  2. Open a new MS Excel sheet.

  3. Assuming problems 1-5 shown in Table 5.7 are computed sequentially in the order shown,

    1. Calculate in MS Excel the result of each expression.

    2. Repeat these calculations using Python interactive mode. Use the same variable names as in the equation.

  4. Fill in the table in your Word document, using 4 decimal places when necessary.

  5. Repeat steps 3 and 4 for problems 6-10 in Table 5.8. Perform these calculations on the values of \(a\), \(b\), \(c\), \(d\), and \(e\) that you computed in problems 1-5. It helps to put the results from problems 1-5 in the same row/column in MS Excel, and put them in a list in Python e.g values = [a, b, c, d, e].

Hint

Remember the order of operations. You will need to import the math and statistics modules to do some of the calculations in Python.

Table 5.7 Equations in MS Excel and Python#

Problem Number

Equation

MS Excel Calculations

Python Calculations

1

\(a = 5\)

2

\(b = a^{1/3}\)

3

\(c = \sin(\sqrt{b})\)

4

\(d = \lfloor -90.5 \rfloor\)

5

\(e = 254 \text{ mod } 66\)

Hint

\(\lfloor \, \rfloor\) denotes the floor operation. See floor and ceiling functions

Consider the values of \(a\), \(b\), \(c\), \(d\), and \(e\) computed above to be a data set, and use them to answer questions 6-10 in the table below. Use built-in or imported functions for each calculation. Round to four decimal places where necessary.

Hint

In Python, create a list that contains these values.

Table 5.8 Calculations in MS Excel and Python#

Problem Number

Calculation

MS Excel Calculations

Python Calculations

6

Find the mean

7

Find the median

8

Find the maximum

9

Find the range

10

Find the standard deviation

Part B#

Answer the following questions and include the answers in your previously created MS Word document:

  1. What differences did you notice between the MS Excel calculations and the Python calculations?

    a. You can add a fifth column with the heading “Differences” to the table from Part A to answer this question.

  2. What Python function did you use to output these variables to the screen? Did you have to use an imported library in Python, or was the function built into the standard library?

  3. What syntax differences exist between Python and MS Excel? Be specific.

Save the MS Word document as a PDF with the name py1_ind_1_username.pdf.