Modules Practice Assignments

Overview

Submission Instructions

For each of the following practice assignments, save your solution in a .py file, with the name being modules and the number of the assignment. For example, for "Modules01: Dice Simulator", save your solution in a file named modules01.py (notice the lowercase "m"). Then, submit that file the respective assignment on codePost.io.
To register for a free codePost account, please follow these instructions.
You can submit to codePost multiple times if you want. Only your last submission will be graded. Watch this short video for a demonstration of submitting an assignment, reviewing the results and resubmitting:
YouTube video: CPSC 1301K: Submitting Practice Assignments

Practice Assignments

Modules01: Dice Simulator

Write a program in Python that simulates the roll of a 6-sided die and an 8-sided die. Generate a random number for the 6-side die and store it in a variable named die1. Generate a random number for the 8-side die and store it in a variable named die2.

Provided code:
import random

''' Put your code here '''

# Display the dice values (do not change the following line!)
print("You rolled two dice:", die1, "and", die2)
Note: Submit your code with the print("You rolled two dice:", die1, "and", die2) statement.

Modules02: Square Garden

You have a square garden and want to build a fence around it. Write a program in Python that calculates the total length of fence you will need to surround the garden.
Your program should:

  1. prompt the user to enter the area of the square garden. Store the area in a variable named area. Hint: The side of the square is equal to the square root of the area of the garden.
  2. calculates how many meters of fence you will need to surround the garden and stores the perimeter into a variable named total_fence. Hint: You have to calculate the perimeter of the square garden which is four times the length of one side.

Example 1:
Please enter the area of the garden: 81
You will need 36.0 meters of fence
Example 2:
Please enter the area of the garden: 25
You will need 20.0 meters of fence

Provided code:
import math

# Write your code here

# Print the total meters of fence (do not change the following line!)
print( "You will need", total_fence, "meters of fence" )
Note: Submit your code with the print( "You will need", total_fence, "meters" ) statement.

Modules03: Random Number

Write a Python program that generates a random number between 10 and 20 (not including 10 and 20). Store the randomly generated number in a variable named number.

Provided code:
# Write your code here

# Display the number (do not change the following line!)
print("The randomly generated number is:", number)
Note: Submit your code with the print("The randomly generated number is:", number) statement. Do not change this line.

Modules04: Mathematical Constant e

Write a Python program to display the value of the mathematical constant e supplied by the math module (see https://docs.python.org/3/library/math.html).

Modules05: Pi

Write a Python program to display the value of the pi supplied by the math module (see https://docs.python.org/3/library/math.html).

Modules06: Pizza Area

For this assignment, write a Python program that calculates and displays the area of a pizza. Complete the Python program so that it

  1. prompts the user to enter the diameter of a pizza
  2. calculates the area of the pizza and stores the result in a variable named area
The area of a circle is calculated by π * r2, where r is the radius (which is half of the diameter). For this assignment, you must use the math module to get the value of π (pi).

Provided code:
# Write your code here

print("The area of the pizza is:", area)