Python Forum
C to Python code conversion print problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C to Python code conversion print problem
#1
Hello! I need to convert this C code I made to Python:
https://gist.github.com/anakk1n/dadf2216...10c3839af5

My python code looks like this:
def algoritm2(v, n, d, c):
    p = 0
    j = -3
    k = 0
    for i in range(n-1):
        if (j >= n - 2):
            break
        if (p == 1):
            print(v[j+1], " ", end='')
            u = k = v[j + 1]
            i = j + 1
            c = c + 1
            p = 0
        else:
            u = -1
        j = i
        aux = v[i] + d + 1
        if (aux <= v[i + 1] and u == -1):
            print(v[i], " ", end='')
            k = v[i]
            c = c + 1
        else:
            if (((v[i] - v[i - 1] >= d) and u != v[i]) or (i == 0)):
                k = v[i]
                print(v[i], " ", end='')
                c = c + 1
            while (aux > v[j + 1] and j < n - 2):
                j = j + 1
                p = 1
    if (v[n - 1] - k >= d + 1):
        print(v[n-1], " ", end='')
    return c
Problem is that it doesn't list 100% the same thing. Did i do anything wrong in the conversion? Also, I changed the 'l' variable in the C code with the 'c' variable in python and in Python I made it return 'c', but it shouldn't affect my result
Reply


Messages In This Thread
C to Python code conversion print problem - by anakk1n - May-21-2020, 07:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem Converting Tradingview Indicator to Python code kralxs 1 447 Apr-27-2024, 06:10 PM
Last Post: kralxs
  problem with print command in super() akbarza 5 789 Feb-01-2024, 12:25 PM
Last Post: deanhystad
  problem with spliting line in print akbarza 3 529 Jan-23-2024, 04:11 PM
Last Post: deanhystad
  problem with print lists MarekGwozdz 4 841 Dec-15-2023, 09:13 AM
Last Post: Pedroski55
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,251 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  Problem with print variable in print.cell (fpdf) muconi 0 723 Dec-25-2022, 02:24 PM
Last Post: muconi
  I need to add data types to cython conversion python to c Good_AI_User 1 1,109 Aug-19-2022, 07:52 AM
Last Post: Gribouillis
  Problem with importing Python file in Visual Studio Code DXav 7 5,566 Jun-15-2022, 12:54 PM
Last Post: snippsat
  Conversion of Oracle PL/SQL(packages, functions, procedures) to python modules. DivyaKumar 2 6,689 Jul-09-2020, 04:46 PM
Last Post: srikanth7482
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,943 Jun-18-2020, 04:59 PM
Last Post: QTPi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020