for answer in QF:
ans = "{:.2f}".format(answer)
if ans in "0.00j":
print(ans.replace("0.00j", ""))
else:
print(ans)
If there is 0.00j in the answer, I have to delete it and print it out, so I used the replace function You keep saying
Calculated answer is(are): -3.73+0.00j -0.27-0.00j
This is how 0.00j is printed. What's the problem? Python masters, help!
python
The third line, if an "0.00j": is if an "0.00j" in an: Please change it to
You used the replace function normally, but it is a matter of condition that the function is not operated.
So the overall code should be changed as below
for answer in QF:
ans = "{:.2f}".format(answer)
if "0.00j" in ans:
print(ans.replace("0.00j", ""))
else:
print(ans)
789 M2 Mac fails to install rbenv install 3.1.3 due to errors
867 Uncaught (inpromise) Error on Electron: An object could not be cloned
775 GDB gets version error when attempting to debug with the Presense SDK (IDE)
1253 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2025 OneMinuteCode. All rights reserved.