[Solved] programing function in python

I changed 2 things : while n > 1: instead of while n > 0: otherwise your loop never stops n=n//10 instead of n=n/10, where // is the euclidian division, which is what you need here You should try this : def testD(D,n): if D % 2 == 0: return 0 count = 0 while … Read more

[Solved] JavaScript function to add two numbers is not working right

HTML DOM element properties are always strings. You need to convert them to numbers in your usage. parseInt(form.resistance.value); parseFloat(form.resistance.value); +form.resistance.value; (Any of the three will work; I prefer the first two (use parseInt unless you’re looking for a float).) solved JavaScript function to add two numbers is not working right

[Solved] A function object:

A function object is an instance of a class that defines the parenthesis operator as a member function. When a function object is used as a function, the parenthesis operator is invoked whenever the function is called. Consider the following class definition: class biggerThanThree { public: bool operator () (int val) { return val > … Read more

[Solved] Write a function named containsLetter that identifies all of the strings in a list that contain a specified letter and returns a list of those strings [closed]

Is this ok ? >>> def containsLetter(searchLetter, hulkLine): … return [x for x in hulkLine if searchLetter in x] … >>> containsLetter(‘i’, hulkLine) [‘like’, “i’m”] >>> Or >>> filter(lambda x: searchLetter in x, hulkLine) [‘like’, “i’m”] >>> 4 solved Write a function named containsLetter that identifies all of the strings in a list that contain … Read more

[Solved] how to write a function for numbers

You’re already given the function signature: int largest(), so that’s exactly how you’d write the function (exactly like int main();): // Declares the function int largest(); // Defines the function: int largest() { // The function MUST return an int (or something convertible) otherwise it will not compile return 0; } Or you can combine … Read more

[Solved] retrieve data from db using function pdo

Change the function to this: function run_db($sqlcom,$exe){ $conn = new PDO(‘mysql:host=localhost;dbname=dbname’, ‘usr’, ‘pass’); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare($sqlcom); $stmt->execute($exe); return $stmt; } and the call to that function to: try { $stmt = run_db(‘SELECT * FROM posts WHERE status= :published ORDER BY id DESC LIMIT 5’,array(‘:published’ => ‘published’)); while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { $contents = … Read more