list out of range how can i fix this and app;y the score

Question:

machine_specs = [] 

for spec in ("Name", "Speed in MHz", "Cores", "Cache in kB", "RAM in GB"):
    data_set = []
    data_val = input(f"{spec}: ")
    if spec == "Speed in MHz":
        data_val = float(data_val)
    elif spec != "Name":
        data_val = int(data_val)
    data_set.append(data_val)
machine_specs.append(data_set)

def score_machine(data):
    score = (
        data[1] / 3 * 25 
      + data[2] / 8 * 25
      + data[3] / 32 * 25
      + data[4] / 8 * 25
    )
    return round(score)

for ms in machine_specs:
    print(f"{ms[0]} scores {score_machine(ms)} out of 100")

this is supposed to give a score based on the data you input into the program to give a score out of a hundred based on your specifications their is a problem though

Asked By: MBenz124

||

Answers:

You are assigning data_set = [] in each iteration, So change like this. I think you might also be required to add another loop to get more data into machine_specs.

machine_specs = []
data_set = []
for spec in ("Name", "Speed in MHz", "Cores", "Cache in kB", "RAM in GB"):
    data_val = input(f"{spec}: ")
    if spec == "Speed in MHz":
        data_val = float(data_val)
    elif spec != "Name":
        data_val = int(data_val)
    data_set.append(data_val)
machine_specs.append(data_set)
Answered By: Rahul K P
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.