CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Decimal to Binary in Python Code Error (https://www.cfd-online.com/Forums/openfoam-post-processing/239121-decimal-binary-python-code-error.html)

thebrokenheartcoder October 21, 2021 10:01

Decimal to Binary in Python Code Error
 
I was trying to convert Decimal to Binary, there is no error in the code but while executing I am getting blank, not showing anything. Could someone help me figure out where is the mistake

Code:

def decimalToBinary(ip_val):
    if ip_val= 1:
    # recursive function call
        decimalToBinary(ip_val // 2)
   
    # printing remainder from each function call
    print(ip_val % 2, end = '')
 
# Driver Code
if __name__ == '__main__':
    # decimal value
    ip_val = 24
   
    # Calling special function
    decimalToBinary(ip_val)

I have read this article to understand the concept and tried this.

Tobermory October 21, 2021 12:11

As a start, line 2:
Code:

if ip_val= 1:
should be
Code:

if ip_val >= 1:
That should help.


All times are GMT -4. The time now is 13:39.