Language:EN
Pages: 3
Words: 641
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
input list scores will result equal tma weightings

Input list scores will result equal tma weightings

Solved Step by step with explanation of calculating weighted average

Question

This question provides an opportunity for you to demonstrate your understanding of the problem-solving approach taught in TM112 and the patterns introduced in Block 1 Part 4 and Block 2 Part 2 . You can find an overview of the problem-solving approach and a list of all the patterns TM112 teaches in the Problem solving and Python quick reference and you will need to refer to this document as you work on the question. Important note: you do not need to get a working program in part(a) in order to attempt part(b). A student wants to design and implement a Python program to determine their weighted average assignment score on a module. Unlike TM112, you can assume that this is a module where the TMAs are equally weighted. There are many ways of doing this, but here is their initial top-level decomposition. > Determine weighted average >> Input a list of TMA scores >> Calculate the TMA weighting >> Create a new list that contains the weighted TMA scores >> Add up the decimal values in the new list >> Print result rounded to the nearest whole number a.In this part you will consider only this part of the top-level algorithm: >> Input a list of TMA scores >> Calculate the TMA weighting >> Create a new list that contains the weighted TMA scores In order to test your code you should also add the step >> print the new list You can assume that there is at least one TMA score, and your program should work regardless of the number of TMAs on the module. One of the tests of your code should be for a module with 4 equally weighted TMAs. The first three scores are 65, 81 and 72. The fourth score is given by the first two digits of your PI number. So, for example, for the PI number B9081720, your scores input list would be: [65, 81, 72, 90] An input list of 4 scores will result in equal TMA weightings of 100/4 = 25% = 0.25, which would produce the output list [16.25, 20.25, 18.00, 22.50] .Implement your algorithm as Python code. Your code must match the steps of your algorithm and you should use comments in the code to make it clear how the two correspond. Remember that your code must work for an input list of any length greater than or equal to 1. Marks will be lost if the program does not follow the algorithm. Copy your Python code, as text, into your Solution document. Name your Python file Q2a_OUCU.py, where ‘OUCU’ is your OU computer username, e.g. abc123. Then include the code file in your TMA zip file.

Answer

Solved Step by step with explanation of calculating weighted average

def calculate_weighted_average(scores):

Returns:

The weighted average of the scores.

weighted_scores.append(score * weighting)

return weighted_scores

"""

scores = input("Enter a list of scores separated by spaces: ").split()

This code first defines a function called calculate_weighted_average(). This function takes a list of scores as input and returns a list of the weighted scores. The weighting is calculated as 1.0 / len(scores), which means that each score is equally weighted. The function then iterates through the list of scores and multiplies each score by the weighting. The results are then stored in a new list called weighted_scores. The function returns the weighted_scores list.

The main function reads a list of scores from the user and then calls the calculate_weighted_average() function. The results of the calculate_weighted_average() function are then printed to the console.

This list of scores will result in the following output:

The weighted scores are: [16.25, 20.25, 18.00, 22.50]

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Victor Page

PageId: DOCE13F649