PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, December 22, 2022

[FIXED] How to convert this function from javascript to python?

 December 22, 2022     function, javascript, python, syntax, syntax-error     No comments   

Issue

Does anybody know how to convert this javascript function to python ?

javascript:

function ding(t, a, e, n) {
  return t > a && t <= e && (t += n % (e - a)) > e && (t = t - e + a), t
}

This is my try on doing so:

def ding(t, a, e, n):
    return t > a and t <= e and (t + n % (e - a)) > e and (t = (t - e + a)), t

It returns a syntax error at the "=" in (t = (t - e + a)) and idk how to solve this right.

When giving it these values: ding(53, 47, 57, 97) it should return 50 in the original javascript function.


Solution

Does it have to be a one-liner? Why not just split it into a few lines:

def ding(t, a, e, n):
    if t > a and t <= e:
        t += n % (e - a)

        if t > e:
            t -= e - a
    
    return t
    
print(ding(53, 47, 57, 97)) # 50


Answered By - lusc
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing