Click here to Skip to main content
15,886,001 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I would like to change the PHP function to Python function.
here is the PHP code:
PHP
function is_length_between($var, $minValue, $maxValue){
$len = strlen(strval($var));
if($len >= $minValue && $len <= $maxValue){return true;}
return false;}
function is_length_equal_to($var, $value){return strlen(strval($var)) == $value;}


What I have tried:

Is there anyone can help me to solve this problem?
Python
def is_length_between()
def is_length_equal_to()
Posted
Updated 15-Jan-20 1:50am

What have you tried?
Where are you stuck?
What help do you need?

To be honest, if you can't translate two trivial pieces of code like that, you need to do two things:
1) Learn the basics of PHP.
2) Learn the basics of Python.
Then use the first to write new functions in the second.

I'm no expert in either language, but I could still finish this trivial homework exercise in a couple of minutes, including extensive testing ... so why can't you?

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
 
Share this answer
 
v2
 
Share this answer
 
Hi above cone in python

Python
<pre>def is_length_between(var,minValue,maxValue):
    slen = len(var)
    if slen >= minValue && slen <= maxValue:
        return true
    return false

def is_length_equal_to(var, value):
    slen = len(var)
    return slen
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900