0% found this document useful (0 votes)
7 views4 pages

CSC/DSCI 1301 Week 03 Lab Assignment

This lab assignment for CSC/DSCI 1301 focuses on integer and floating-point arithmetic, precedence rules, and using Python modules. Students are required to complete three programming tasks: estimating calories burned during exercise, converting cents into coins, and calculating the volume of a sphere and factorial of a random number. Deliverables include source code and screenshots of the program outputs, with specific naming conventions for files.

Uploaded by

Zion Akinode
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

CSC/DSCI 1301 Week 03 Lab Assignment

This lab assignment for CSC/DSCI 1301 focuses on integer and floating-point arithmetic, precedence rules, and using Python modules. Students are required to complete three programming tasks: estimating calories burned during exercise, converting cents into coins, and calculating the volume of a sphere and factorial of a random number. Deliverables include source code and screenshots of the program outputs, with specific naming conventions for files.

Uploaded by

Zion Akinode
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lab Assignment Week 03

CSC/DSCI 1301 – Principles of CS/DS I

Week of September 8 th , 2025

Introduction
Welcome to the third programming lab of CSC/DSCI 1301! Today, we will be covering the following
topics:

• Integer and floating-point arithmetic


• Precedence rules for arithmetic expressions
• Using the floor division operator
• Importing modules
• Using the Math and Random modules

Comments
The lab assignment requires the inclusion of comments to enhance code readability and understanding.
Specifically, a block comment at the beginning of the Python file is required. Your block comment should
include the following:

• The program name


• The author’s name (your name)
• A description of the program’s overall purpose

Additionally, inline comments should be used throughout the code to explain specific lines or sections
that might be less obvious to someone reading the code. These inline comments can clarify complex
calculations, explain the purpose of certain variables, or provide additional context for specific code
blocks.

Lab policy reminders:


• Attendance is mandatory.
• Labs must be completed individually.
• TAs are here to help you. Ask them for help!

Deliverables
Your submission to iCollege must include the following items:

1. The source code of your program. ( .py files!)


2. A screenshot of the terminal output of your program

If you have any questions, please do not hesitate to ask your TA!
Program 1: [Link]
For the first program in today’s lab, you will need to write a program that estimates the average calories
burned for a person when exercising. You will need to implement the following equation as a Python
expression:
(𝐴𝑔𝑒 × 0.2757 + 𝑊𝑒𝑖𝑔ℎ𝑡 × 0.03295 + 𝐻𝑒𝑎𝑟𝑡 𝑅𝑎𝑡𝑒 × 1.0781 − 75.4991) × 𝑇𝑖𝑚𝑒
𝐶𝑎𝑙𝑜𝑟𝑖𝑒𝑠 =
8.368
You will need to gather the following information from the user:

1. Age – The user’s age in years


2. Weight – The user’s weight in pounds
3. Heart Rate – The user’s heart rate in beats per minute
4. Time – The length of the workout in minutes

Example Output
Your output should be formatted like the image below. The floating-point value must be formatted to
display only two digits after the decimal point. This will require using f-strings in your print()
functions. See the Python statement below.
print(f'Calories burned: {calories:.2f}')

Skills Covered
• Integer and floating-point arithmetic
• Precedence Rules for Arithmetic Expressions

Deliverables
For this program, you will need to provide the Python file containing your code as well as a screenshot of
the output of your program. Please name your files as follows:

• Python Files
o lastname_firstname_filename.py
o For example: turing_alan_calories.py
• Screenshots
o lastname_firstname_filename.png
o For example: turing_alan_calories.png
Program 2: [Link]
For your second program, you will write a program that converts a user-entered number of cents into
the fewest number of US coins of that amount. US currency has four different types of coins: quarters
(25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent). You will need to use the floor
division operator to solve this problem. Your program must prompt the user to enter a number of cents
in the terminal. Hint: Start with the largest denominations first! Subtract the value of the previous
denomination before calculating the next.

The output of this program should be counts of each type of coin that represents this value. Your
solution must be the fewest set of coins that equal the number of cents entered by the user.

Example Output
Your output should be formatted like the image below.

Skills Covered
• Integer Arithmetic
• Using the floor division operator

Deliverables
For this program, you will need to provide the Python file containing your code as well as a screenshot of
the output of your program. Please name your files as follows:

• Python Files
o lastname_firstname_filename.py
o For example: turing_alan_change.py
• Screenshots
o lastname_firstname_filename.png
o For example: turing_alan_change.png
Program 3: [Link]
For your third program, you will write a program that uses the constants and functions that are part of
the Math and Random modules for Python. Your program will:

1. Calculate the volume of a Sphere.


2. Calculate the factorial of a randomly generated number between 1 and 10.

The formula for the volume of a sphere is shown below. You must write a Python expression for the
following equation using the pi constant and the pow() function in the Math module.

4 3
𝑉𝑜𝑙𝑢𝑚𝑒 = 𝜋𝑟
3
Your program should prompt the user to enter the radius of the sphere, calculate the volume of the
sphere, and print the result to the terminal. The floating-point value must be formatted to display only
two digits after the decimal point. This will require using f-strings in your print() functions.

To generate a random number between 1 and 10, you must use the randInt() function in the random
module. To compute the factorial of a number, you will need to use the factorial() function in the
math module.

Example Output
Your output should be formatted like the image below.

Skills Covered
• Importing modules
• Using the Math and Random modules

Deliverables
For this program, you will need to provide the Python file containing your code as well as a screenshot of
the output of your program. Please name your files as follows:

• Python Files
o lastname_firstname_filename.py
o For example: turing_alan_modules.py
• Screenshots
o lastname_firstname_filename.png
o For example: turing_alan_modules.png

Common questions

Powered by AI

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 .

You might also like