CompSci
  • Home
  •  Unit 1
    Output Exercises
     Unit 2
    Variables Math Modules Exercises
     Unit 3
    Conditionals Exercises
     Unit 4
    Iteration / Loops Exercises
     Unit 5
    Strings Exercises
     Unit 6
    Lists Exercises
     Unit 7
    Functions Exercises
  •  Unit 1
    Java Introduction Java Syntax Errors & Coding Conventions Format Method Exercises
     Unit 2
    Variable Introduction Math / Arithmetic Operators Obtaining a Value Formatting Numeric Output Concatenation & Constants Division & Type Casting Exercises
     Unit 3
    Conditionals Exercises
     Unit 4
    while Loops for Loops Exercises
     Unit 5
    Strings Exercises
     Unit 6
    Methods Method Parameters Method Return Types Exercises
  • Muddy City
  • Github Classroom
  •  Assignments
    Add an Assignment Edit Assignment Search Program Code
     Forum
    Ask a Question Search the Forum
     New Account
    New Account


Account Mgmt
Reset Password

Python - Variables & Math


Exercises

Utensils

Difficulty: Low

Title: Utensils

Description:
Camryn is unpacking a box of utensils. The total weight of the box of utensils is x lbs and it contains x forks.

  • Have user input to enter the weight of each box
  • Have user input to enter the number of utensils in each box
What is the weight of each fork?

Topics Covered
  • User input
  • Division
  • Outputting text and variable values

Output:
Input the weight of each box: 4 Input the number of forks per box: 16
Each fork weights: 0.25 lbs


Moving

Difficulty: Low

Title: Moving

Description:
Carrie is packing to move to another apartment down the hall. She packed x boxes. Each box can hold up to z lbs. The trolley she is using to move can take up to 32 lbs. How many trips does it take her to move if she only has one trolley?

Topics Covered

  • User input
  • Division

Output:
Input the number of boxes: 24
Input how much weight each box can hold 8

Carrie can take 4 boxes per trip
Carrie must make 6 trips


Input the number of boxes: 14
Input how much weight each box can hold 12

Carrie can take 2 boxes per trip
Carrie must make 7 trips


Office Supplies

Difficulty: Low

Title: Office Supplies

Description:
An office supply company truck can take up to x lbs of cargo. Oliver packed z boxes; each box can weigh up to 34 lbs. After Oliver loaded all the boxes, the truck can take about ___________ lbs more of cargo?

  • Get user input to determine how much cargo the office supply truck can hold.
  • Get user input to determine how many boxes Oliver packed.
  • Format the output with commas (see output example).
From the same office supply company, Hannah ordered some office supplies. When the supplies were delivered, they came in 2 boxes. The total weight of the two boxes was 44 lbs. What is the individual weight of the two boxes, assuming one of the boxes was at max weight?

Output:
Input the total lbs the truck can deliver: 4530
Input how many boxes Oliver loaded: 50

Oliver can carry 2,830 more pounds of cargo
Hannah's first box weight ____ and the second box weighed ____


Reverse the Numbers

Difficulty: Medium

Title: Reverse the Numbers

Description:
Write a program to reverse the digits of a given integer.

  • User input to get a three digit number (ex. 100 to 999).
  • Save the input to a variable.
  • Break the input into the hundreds place, tens place, and ones place.
  • Use math operations to reverse the number.

NOTE: You MUST use math operators to solve this problem. Do NOT use String methods.

Output:
Input: 123
321


Surface Area

Difficulty: Medium

Title: Surface Area

Description:
Write a program to calculate the Surface Area of a Cylinder:

The surface area of a cylinder can be calculated using the formula:
A = 2πrh + 2 πr2

  • Prompt the user for the radius of the cylinder.
  • Prompt the user for the height of the cylinder.
  • Format the output to 2 decimal places.

Output:
Radius: 5
Height: 20

The area is: 785.40


Radius: 10
Height: 5

The area is: 942.48


BMI

Difficulty: Medium

Title: BMI

Description:
Write a program to calculate a users Body Mass Index (BMI) using the following formula:
weight (lb) / [height (in)]2 x 703

  • Prompt the user for their weight in pounds (lb) and ounces (oz).Ounces (oz) must be changed to decimal values (NOTE: 1 lb = 16 oz)
  • Prompt the user for their height in inches.
  • Output the users BMI.
  • Round the answer to two decimal places (see output).
Example Let’s calculate Sam’s BMI using the English numeric system. His weight is 37 pounds and 4 ounces and his height is 41 1/2 inches.

Convert ounces and fractions to decimals:
  • Weight of 37 lbs and 4 oz = 37.25 lbs (16 ounces = 1 pound so 4 oz/16 oz = 0.25).
  • Height = 41.5 in.
  • (37.25 lbs / 41.5 in / 41.5 in) x 703 = 15.2

Output:
Weight lbs: 37
Weight oz: 4
Height: 41.5

BMI: 15.2



Computer Science