-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Electric power #3976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Electric power #3976
Conversation
@cclauss hello, sir please debug it and give me some tips and instructions, some lines in code are longer then 79 so what should i need to do???? |
Maximum line length is 88 characters. |
electronics/electric_power.py
Outdated
result = (float(voltage * current)) | ||
if result < 0: | ||
result = result * -1 | ||
return {'power': result} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the builtin function abs()
https://docs.python.org/3/library/functions.html#abs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
@cclauss all done sir. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's spice up the tests and let's return a namedtuple instead of a dict. Namedtuples are more optimized than dicts and they provides helpful names.
electronics/electric_power.py
Outdated
>>> electric_power(voltage=2, current=2, power=0) | ||
{'power': 4.0} | ||
>>> electric_power(voltage=-2, current=3, power=0) | ||
{'power': 6.0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to test:
- No zeros
- Two zeros
- Negative numbers for power
- Floating-point numbers
{'power': 6.0} | |
>>> electric_power(voltage=-2, current=3, power=0).name | |
'power' | |
>>> electric_power(voltage=-2, current=3, power=0).value | |
6.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, should i also do this on ohms_law as well??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this PR landed before you modify Ohm's law...
Coincidentally, @rhettinger (who wrote the namedtuple) just tweeted about Ohm's law...
https://twitter.com/raymondh/status/1331850115674345473
@@ -0,0 +1,33 @@ | |||
# https://en.m.wikipedia.org/wiki/Electric_power | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from collections import namedtuple | |
result = namedtuple("result", "name value") | |
electronics/electric_power.py
Outdated
fundamental value of electrical system. | ||
examples are below: | ||
>>> electric_power(voltage=0, current=2, power=5) | ||
{'voltage': 2.5} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{'voltage': 2.5} | |
result(name='voltage', value=2.5) |
electronics/electric_power.py
Outdated
"Power cannot be negative in any electrical/electronics system" | ||
) | ||
elif voltage == 0: | ||
return {"voltage": power / current} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {"voltage": power / current} | |
return result("voltage", power / current) |
@cclauss sir run this code and you will see that with floating point values it will give you very long decimal value output, so my question is how to wrapped it, to only for 3 values after decimal point |
@cclauss I figured out, now all done??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
* Electric power * updated as suggested by cclauss * updated as suggested by cclauss * decimal value error * All done
* Electric power * updated as suggested by cclauss * updated as suggested by cclauss * decimal value error * All done
* Electric power * updated as suggested by cclauss * updated as suggested by cclauss * decimal value error * All done
* Electric power * updated as suggested by cclauss * updated as suggested by cclauss * decimal value error * All done
Describe your change:
Used code from ohms_law algorithm, but now for power calculation
Checklist:
Fixes: #{$ISSUE_NO}
.