Home > Software engineering >  How can I input the values of 2 lists into a math equation
How can I input the values of 2 lists into a math equation

Time:05-03

I have two lists, probability[] and miss[]

I need to plug my 2 lists into a formula. severity = probability* 100,000 / miss

When I print(probability), I get 0.000001731517 0 0 0 and when I print(miss), I get 6954 12507 3621 10440

This is my attempt at plugging them into the formula.

severity=[]
for i in range(len(severity)):
    severity[i] = (probability[i]*100000/miss[i])
    print(severity[i])

What am I doing wrong? it doesn't even make it into the for loop

CodePudding user response:

Your list is empty, so when you run the for loop, it is equivalent to for i in range(0), which means it does not make it into the for loop.

You should do

severity=[]
for i in range(len(probability)):
    severity.append(probability[i]*100000/miss[i])
    print(severity[i])

CodePudding user response:

You could use numpy instead and then you don't need a for loop:

import numpy as np
severity = np.array(probability)*100000/np.array(miss)

CodePudding user response:

Using list comprehension you can write

severity = [p*100_000/m for p,m in zip(probability, miss)]
  • Related