OneCompiler

Hslip10

150

Q1]

<!DOCTYPE html> <html> <head> <title>Math Operations</title> </head> <body> <form method="post" action=""> <label for="num1">Enter the first number:</label> <input type="text" name="num1" required>
<label for="num2">Enter the second number:</label>
<input type="text" name="num2" required>

<input type="submit" value="Submit">
</form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $num1 = $_POST["num1"]; $num2 = $_POST["num2"]; // a. Find mod of the two numbers $modResult = findMod($num1, $num2); echo "<p>Mod of $num1 and $num2: $modResult</p>"; // b. Find the power of the first number raised to the second $powerResult = findPower($num1, $num2); echo "<p>$num1 raised to the power of $num2: $powerResult</p>"; // c. Find the sum of first n numbers (considering the first number as n) $sumResult = findSum($num1); echo "<p>Sum of first $num1 numbers: $sumResult</p>"; // d. Find the factorial of the second number $factorialResult = findFactorial($num2); echo "<p>Factorial of $num2: $factorialResult</p>"; } // Function to find mod of two numbers function findMod($num1, $num2) { return $num1 % $num2; } // Function to find the power of the first number raised to the second function findPower($num1, $num2) { return pow($num1, $num2); } // Function to find the sum of the first n numbers function findSum($n) { return ($n * ($n + 1)) / 2; } // Function to find the factorial of a number function findFactorial($num) { if ($num == 0 || $num == 1) { return 1; } else { return $num * findFactorial($num - 1); } } ?> </body> </html>

Q2]
a]
import pandas as pd

Load the SOCR-HeightWeight dataset

dataset = pd.read_csv('SOCR-HeightWeight.csv')

Display column-wise mean

mean_values = dataset.mean()
print("Column-wise Mean:\n", mean_values)

Display column-wise median

median_values = dataset.median()
print("\nColumn-wise Median:\n", median_values)

B]
from itertools import combinations

Function to compute Manhattan distance between two points

def manhattan_distance(point1, point2):
return abs(point1[0] - point2[0]) + abs(point1[1] - point2[1])

Function to compute sum of Manhattan distance between all pairs of points

def sum_manhattan_distance(points):
pairs = combinations(points, 2)
total_distance = sum(manhattan_distance(p1, p2) for p1, p2 in pairs)
return total_distance

Example usage

points = [(1, 2), (3, 5), (7, 8), (4, 6)]

result = sum_manhattan_distance(points)
print("Sum of Manhattan distance between all pairs of points:", result)