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.
Please use the builtin function abs()
https://docs.python.org/3/library/functions.html#abs
|
@cclauss all done sir. |
cclauss
left a comment
There was a problem hiding this comment.
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.
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.
Okay, should i also do this on ohms_law as well??
There was a problem hiding this comment.
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.
| 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.
| {'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.
| 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??? |
* 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}.