Custom Assignments

Click the information icon to review any section

M03 Custom Exercise #1 (Random Numbers File)

Assignment Instructions

Create a program that writes a series of random numbers to a file, then reads the file to calculate the average of those numbers, as well as the highest and lowest numbers. Prompt the user for how many random numbers they want to add to file. If the number is less than 100, add at least 100 numbers.

Each random number should be between 10 and 500, inclusive (at least 10, no more than 500). Create the file as YourName_randomnumbers.txt (where YourName is your actual name or initials...)

Once the program creates the file, open and read in all numbers. Loop through the numbers and determine the highest number, the lowest number, count how many entries are in the file, and calculate the average of all numbers.

Remember to use functions and comment as needed. Submit your .py file and your randomnumbers.txt file.

Output example
M03 Custom Exercise #1 Sample Output

Figure 1: M03 Custom Exercise #1 Sample Output

M03 Custom Exercise #2 (File Read Exceptions)

Assignment Instructions

Download the badnumbers.txt file below. Create a program to read each line, convert it to a float and ddisplay the number. Use try-except blocks within the file read loop to handle bad lines. Print an errror message when any bad line is encountered. Count and display the number of good lines.

Output example
M03 Custom Exercise #2 Sample Output

Figure 2: M03 Custom Exercise #2 Sample Output

M03 Custom Exercise #3 (Count Tracker Steps from File)

Assignment Instructions

Download the mysteps.txt file from the link below. This file contains the number of daily steps taken during 2019 and part 2020 (from a Fitbit or similar tracker). The data in each row of the file represents year,month,day,steps. The delimiter for each row is a comma (this is what is commonly refered to as a CSV format).

Write a Python program to read the entire file and calculate the average number of steps taken for each month in 2019. Note: there are not records for every date of every month. You must count how many entries are included in each month.

Display 2 averages for each month: 1) the number of steps taken based on the days walked, and 2) the average number of steps taken based on the days in the month. Display the month name on each line with the averages. 20 points. 

Extra credit (10 points): show the number of actual days walked for each month.

Output example
M03 Custom Exercise #3 Sample Output

Figure 3: M03 Custom Exercise #3 Sample Output