Dec 03, 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#
Open the MS Word template:
py1_ind_1_username.docx
Open a new MS Excel sheet.
Assuming problems 1-5 shown in Table 5.7 are computed sequentially in the order shown,
Calculate in MS Excel the result of each expression.
Repeat these calculations using Python interactive mode. Use the same variable names as in the equation.
Fill in the table in your Word document, using 4 decimal places when necessary.
Note
You should get the same values for each expression in both MS Excel and Python
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.
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.
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:
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.
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?
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.