Python Forum
P2 -> P3 : Errors - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: P2 -> P3 : Errors (/thread-35778.html)



P2 -> P3 : Errors - wsHVM - Dec-13-2021

I have some code which I believe to be from Python 2 and need to move it to Python 3. I do not code in Python, or I stumble through very simple routines with some luck.

The code below gives me several errors in Python 3. Any suggestions or things I need to address? Any help would be greatly appreciated.


p, q = 1, 3
a, b, a1, b1 = 4, 1, 12, 4
for i in range(10000):
    p, q = p+q, q+2        # next convergent
    a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
    while 1:
        d = a//b
        r = a1 - d*b1      # break if a//b != a1//b1
        if r < 0 or r >= b1: break
        print d,           # common digits
        a, a1 = 10*(a-d*b), 10*r



RE: P2 -> P3 : Errors - bowlofred - Dec-13-2021

Python3 is usually distributed with a converter 2to3 that will attempt to find python2 code that will not run properly under python3, and may be able to fix many of them. You should try running it on the code.

For your code above it appears only to flag the print statement that becomes a function and needs a little bit of conversion.