Preclass 1 test option#
Learning Objectives#
Perform arithmetic operations (i.e., addition, subtraction, multiplication, division,
and exponentiation), in Python while keeping in mind order of operations;
Employ Visual Studio Code to write, edit, and save Python code;
Output Python data from script to screen.
Introduction#
Python 3 is a powerful programming language for performing computations…,
Instructions#
Make sure to fill out all header information, including a short description of the code.
Include all needed import statements in the labeled section of the template.
Hint
The
mathmodule may be useful.In your main script, initialize three variables
a,b, andcwith the values101,7, and12.34respectively that can be used in the calculations.Implement the following three equations in
Pythonusing three more variables to store the results. Use appropriatemathfunction calls where needed. Be careful with order of operations.\(c^2 - \sin(b)^2\)
\(b!\cdot (\cos(\dfrac{\pi}{c})- a)\)
\(\dfrac{c^{\pi e} \sin^{-1}{(\sqrt{3}/2)}}{a^e b}\)
Hint
In
Python, you can compute the inverse of a trigonometric function using themathmodule. For example, the inverse sine function, denoted as\sin^{-1}can be calculated usingmath.asin().After each calculation, print the output to the command window rounded to decimal places. Research f-strings and the format specification mini-language to learn how to round the output to decimal places without changing the stored value.
# Let's do the math part first. Inialize the math library here.
# Uncomment the proper line below to import the math librbary
#import pandas
#import math
#from math import factorial
#import myMath
#import matplotlib.pyplot as plt
#import numpy as np
# Now initialze your variables, a, b and c. variable a is provided as an example.
a = 101
# Now Define the equations.
# Use variable names "eq1","eq2", and "eq3" so that you can check the values at the end
# Make sure you run the code! Otherwise we can't check it.
# Note that there are no print statements in this yet, so you won't see any outputs for the code yet.
'''
This line will check your results for this first part. Click 'run' below to check
'''
from pre0Check import check_math_results
check_math_results(eq1, eq2, eq3)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[2], line 5
1 '''
2 This line will check your results for this first part. Click 'run' below to check
3 '''
4 from pre0Check import check_math_results
----> 5 check_math_results(eq1, eq2, eq3)
NameError: name 'eq1' is not defined
Great! Now let’s setup the actual file. Below is a general setup for your standard ENGR133 python files. Copy over your imports right before the main() function, and then add your variable initializations, and equation deffinitions in the main() function.
Something that you will almost always be expected to do is print out values to the terminal so that they can be recorded. Using “formatted strings” or f-strings as mentioned in step 6 above will make quick work of printing text and numbers effectively.
"""
Course Number: ENGR 13300
Semester: e.g. Spring 2026
Description:
Replace this line with a description of your program.
Assignment Information:
Assignment: e.g. 7.2.1 Py1 Team 1 (for Python 1 Team task 1)
Team ID: ### - ## (e.g. LC1 - 01; for section LC1, team 01)
Author: Name, login@purdue.edu
Date: e.g. 01/23/2026
Contributors:
Name, login@purdue [repeat for each]
My contributor(s) helped me:
[ ] understand the assignment expectations without
telling me how they will approach it.
[ ] understand different ways to think about a solution
without helping me plan my solution.
[ ] think through the meaning of a specific error or
bug present in my code without looking at my code.
Note that if you helped somebody else with their code, you
have to list that person as a contributor here as well.
Academic Integrity Statement:
I have not used source code obtained from any unauthorized
source, either modified or unmodified; nor have I provided
another student access to my code. The project I am
submitting is my own original work.
"""
# Import the Math module here
def main():
if __name__ == "__main__":
main()
Cell In[3], line 42
if __name__ == "__main__":
^
IndentationError: expected an indented block after function definition on line 37
'''
This line will check your string formatting. DO NOT include in your code to Gradescope!
'''
from pre0Check import check_formatting
check_formatting(main)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[4], line 5
1 '''
2 This line will check your string formatting. DO NOT include in your code to Gradescope!
3 '''
4 from pre0Check import check_formatting
----> 5 check_formatting(main)
NameError: name 'main' is not defined