CSC/DSCI 1301 Week 03 Lab Assignment
CSC/DSCI 1301 Week 03 Lab Assignment
To calculate the volume of a sphere, use the formula Volume = 4/3 * π * r³, implemented in Python with the math module's pi constant and pow() function. To calculate the factorial of a random number, use the random module’s randint() function to generate a number between 1 and 10, and the math module’s factorial() function to compute the factorial of that number .
The steps involve using the floor division operator to determine how many of each coin can be obtained from the total cents, starting with the largest denomination (quarters). After each step, the remainder is reduced by the value of the used coins. Starting with the largest denomination is advantageous because it minimizes the number of coins needed, making the conversion efficient and closely mirroring everyday cash transactions .
Python's f-strings are emphasized for formatting output because they allow for precise control over the appearance of floating-point numbers, such as setting the number of decimal places displayed. This is critical for readability and accuracy, especially in calculations, like estimating calories burned where results are expected to be presented with two decimal points .
Requiring individual completion of lab assignments promotes personal responsibility and ensures that students engage deeply with the material, enhancing their understanding and problem-solving skills. It prevents dependency on peers for answers, encouraging self-reliance and increasing individual accountability. However, it can also pose challenges for students struggling without collaborative support, highlighting the importance of accessible TA assistance .
Providing a screenshot of the terminal output ensures that the program not only executes without errors but also produces the expected results as specified in the lab assignment. This serves as a verification for both the student and the instructor that the program behaves correctly under test conditions .
For each program, students must submit the Python source file and a screenshot of the terminal output. These deliverables ensure that students have completed the assignment tasks, allow TAs to verify code correctness and functionality, and help students practice both coding and documentation skills indispensable for effective learning and assessment .
The floor division operator is important when converting a number of cents to US coins because it allows for calculating the maximum number of whole coins that fit into a given amount, starting from the highest denomination. This operator helps in efficiently breaking down the amount into the fewest coins possible, which matches real-world currency transactions .
To estimate calories burned, the formula used is: Calories = (Age × 0.2757 + Weight × 0.03295 + Heart Rate × 1.0781 − 75.4991) × Time / 8.368. When implementing this in Python, it’s important to gather user inputs for age, weight, heart rate, and time. These values should be used in a Python expression respecting the precedence rules, and the result should be formatted to two decimal places using f-strings to provide a readable output .
The lab assignment covers integer and floating-point arithmetic, precedence rules for arithmetic expressions, and the use of the floor division operator. Understanding precedence rules is crucial in programming because it determines the order in which operators are evaluated in expressions, ensuring that calculations are performed correctly without the need for excessive use of parentheses .
Block comments provide an overview of the program’s purpose, author, and name at the start of the file, offering context for the file as a whole. Inline comments are used to explain specific lines or sections, clarifying the purpose of complex calculations, variables, or providing additional context, thereby making the code more understandable, especially for someone reading it for the first time .