Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading