Categories
Mastering Development

Using a function calculate and display the verage of all numbers from 1 to the number entered by the user in python

I am gitting stuck here, please help. The code has to promt the user to enter a number, pass the number to a python function and let the function calculate the average of all the numbers from 1 to the number entered by the user. def SumAverage(n): sum=0 for idx in range(1,n+1): average =sum/idx return […]

Categories
Mastering Development

Create pandas dataframe : map a function over numpy

I am create a pandas dataframe and using numpy to simulate values. I’d like to assign randomly generated ids to two columns in pandas, for which, I wrote a function that returns alphanumeric ids. However, with my current code, it only calls the function once and returns same ids for all rows. I need unique […]

Categories
Android User Help

the app crashes database connectivity

package com.example.databaseconnectivity; import android.content.Context; import android.os.AsyncTask; import android.widget.Toast; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; public class BackgroundTask extends AsyncTask<String,Void,String> { // constructor Context ctx; BackgroundTask(Context ctx){ this.ctx = ctx; } @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected void onPostExecute(String […]

Categories
Mastering Development

Error when sending POST request from React app to Rocket backend returns failure

I’m writing a simple web with Rocket as backend and React as frontend. The code snippet looks like this for login page #[post("/login", data = "<data>")] pub fn login( conn: DbConn, mut cookies: Cookies<‘_>, data: Form<LoginForm>, ) -> Result<JsonValue, NotFound<String>> { let valid_account = match Account::find_by_email(&*conn, data.email.as_str()) { Ok(account) => { if account.password == data.password […]

Categories
CMS Magento Mastering Development

Plugin to fire on customer delete

I am trying to write a plugin (interceptor) to fire when a customer is being deleted in Magento 2. Previously I have written a plugin to fire when a new customer is saved. My plugin for saving makes use of * @param \Magento\Customer\Model\ResourceModel\CustomerRepository $subject * @param CustomerInterface $customer * @param string|null $passwordHash * @return array […]

Categories
Database Development

User-defined function returns first character only although RETURN VARCHAR(10) is defined?

Everyone, I cannot figure out what is missing in the below user-defined function: CREATE OR ALTER FUNCTION ufn_GetSalaryLevel(@Salary money) RETURNS VARCHAR(10) AS BEGIN IF (@Salary < 30000) RETURN ‘Low’; ELSE IF (@Salary <= 50000) RETURN ‘Average’; ELSE RETURN ‘High’; RETURN ”; END; SELECT dbo.ufn_GetSalaryLevel(100440) The output is including only the first character of the ‘Low’/’Average’/’High’ […]

Categories
Mastering Development

Estimating value of 1/pi using Ramajunam equation, returning wrong value when comparing with (1/math.pi)

import math # performing ramanujan’s infinite series to #generate a numerical approximation of 1/pi: “”” 1/pi = (2*sqrt(2))/9801) * (4*k)!*(1103+26390k)/(((k!)**4)*396**(4k)))””” def factorial_1(k): if k==0: return 1 else: m=k-1 result = k* factorial_1(m) return result The factorial works fine have checked with multiple values (more than required). def estimate_pi(): k= int(input(“Enter the Value of k to […]

Categories
Mastering Development

Estimating value of 1/pi using Ramajunam equation, returning wrong value when comparing with (1/math.pi)

import math # performing ramanujan’s infinite series to #generate a numerical approximation of 1/pi: “”” 1/pi = (2*sqrt(2))/9801) * (4*k)!*(1103+26390k)/(((k!)**4)*396**(4k)))””” def factorial_1(k): if k==0: return 1 else: m=k-1 result = k* factorial_1(m) return result The factorial works fine have checked with multiple values (more than required). def estimate_pi(): k= int(input(“Enter the Value of k to […]

Categories
Mastering Development

What to use for covariance over fn parameter in Rust?

today I have learned that rust does not support covariance over an fn parameter only its return type is covariant. (see rust doc) Why did I learn about that fact in rust? Because I tried to implement a very simple game where I have separated the logic, the event handling, and the drawing in three […]

Categories
CMS Magento Mastering Development

How to create export grid listing to csv file in magento with filter and search?

I wrote a controller to export data from grid to CSV. It work fine, but I call the export controller directly and it export all data. It not follow the grid result when user filter. I want to export as the result the grid display when user filter or search. My code as below: /** […]