Logical operators with three lists

Daniele

I have a problem with lists: I have three lists:

Pipe_sizes = [15,15,22,15,32,45]
Flow_rates = [0.1,0.3,1,2,0.4,1.5]
Material_pipes = [Copper, Copper, PVC, Steel, Steel, Copper]

I would like to use logical operators to change the list Pipe_sizes as below:

If the material is Copper, I will use the follow logical operators:
if Flow_rates <= 0.2 then the pipe size is 15
if Flow_rates > 0.2 and <= 1 then the pipe size is 22
if Flow_rates > 1 and <=1.9  then the pipe size is 32
if Flow_rates > 1.9 then the pipe size is 45

And for PVC I will use the follow logical operators:

if Flow_rates <= 0.1 then the pipe size is 15
if Flow_rates > 0.1 and <= 1 then the pipe size is 22
if Flow_rates > 1 and <=1.4  then the pipe size is 32
if Flow_rates > 1.4 then the pipe size is 45

And for Steel I will use the follow logical operators:

if Flow_rates <= 0.1 then the pipe size is 15
if Flow_rates > 0.1 and <= 0.8 then the pipe size is 22
if Flow_rates > 0.8 and <=1.5  then the pipe size is 32
if Flow_rates > 1.5 then the pipe size is 45

If I didn't have the list Material_pipes, it was easy to change the list Pipe_sizes. I could use the follow solution:

def flow_rate_to_size(rate):
    if rate <= 0.2:
        size = 15
    elif 0.2 < rate <= 1:
        size = 22
    elif 1 < rate <= 1.9:
        size = 32
    else:
        size = 45
    return size

Flow_rates = [0.1, 0.3, 1, 2, 0.4, 1.5]
Pipe_sizes = [Flow_rate_to_size(rate) for rate in Flow_rates]
print(Pipe_sizes)

But what can I do if Pipe_sizes depends also from the list Material_pipes?

BlivetWidget

Just pass in both pieces of information and use the appropriate one for the material passed in. Going off of your example.

def flow_rate_to_size(rate, material):
    size = -1 # good to set an error state
    if material.lower() == 'copper':
        if rate <= 0.2:
            size = 15
        elif 0.2 < rate <= 1:
            size = 22
        elif 1 < rate <= 1.9:
            size = 32
        else:
            size = 45
    elif material.lower() == 'pvc':
        if rate <= 0.1:
            size = etc....
    etc...
    return size

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related