Ask Your Question
0

Checking whether the voltage within the range

asked 2023-08-09 03:59:10 -0500

Jimmy gravatar image

My Goal:Checking whether the voltage within the range of 0.9 to 1.05

**My_Code_1:**

ierr, volts = psspy.abusreal(1,1,string='PU')

x1.set_cell ((3, 'z'),'pass' if (0.9 < max(zip(*volts )) < 1.05  and  0.9 < min(zip(*volts ))

             < 1.05) else 'Not Pass')*


**My_Code_1_Result:**  

'Not Pass'

**My_Code_2:**

ierr, volts = psspy.abusreal(1,1,string='PU')

max_value = max(zip(*volts ))

min_value = min(zip(*volts ))

x1.set_cell ((3, 'z'),'pass' if (0.9 < max_value  < 1.05  and  0.9 < min_value< 1.05) else 

             'Not Pass')*


**My_Code_2_Result:**  

'Not Pass'

**My_Code_3:**

tolerance = 1e-6 

ierr, volts = psspy.abusreal(1,1,string='PU')

x1.set_cell ((3, 'z'),'pass' if (0.9+tolerance < max(zip(*volts )) < 1.05-tolerance and 0.9+tolerance < min(zip(*volts)<1.05-tolerance) else 'Not Pass')*


**My_Code_3_Result:**  

'Not Pass'

I checked all the value of max(zip(volts )) and min(zip(volts )).

They are all within 0.9~1.05. But why keep jumping into else shows 'Not Pass' ?

I did it wrong or can't do like this ?

Thank you for reading my question.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2023-08-09 07:03:49 -0500

perolofl gravatar image

The problem is that max(zip(*volts)) returns a tuple, e.g. (1.0404236316680908,) and not a float, so the if-statement doesn't work.

Use max(volts[0]) instead.

A tip is to print the values to check if they have the expected format when the code is not working correctly.

edit flag offensive delete link more

Comments

Thank you for answering my questions. I see. Thank you.

Jimmy gravatar imageJimmy ( 2023-08-10 00:16:25 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2023-08-09 03:59:10 -0500

Seen: 151 times

Last updated: Aug 09 '23