OneCompiler

Hslip19

119
<!DOCTYPE html> <html> <head> <title>String Operations</title> </head> <body> <?php // Function to delete a part of the string function deletePart($str, $position, $numChars) { return substr_replace($str, '', $position, $numChars); }
// Function to insert a small string at a specified position
function insertString($bigStr, $smallStr, $position) {
    return substr_replace($bigStr, $smallStr, $position, 0);
}

// Function to replace characters/words at a specified position
function replaceString($bigStr, $smallStr, $position) {
    return substr_replace($bigStr, $smallStr, $position, strlen($smallStr));
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Getting input from the user
    $sentence = $_POST["sentence"];
    $word = $_POST["word"];
    $position = $_POST["position"];
    $numChars = $_POST["numChars"];

    // Deleting a small part from the first string
    $result1 = deletePart($sentence, $position, $numChars);

    // Inserting the given small string at the specified position
    $result2 = insertString($sentence, $word, $position);

    // Replacing characters/words from the given big string at specified position
    $result3 = replaceString($sentence, $word, $position);
}
?>

<h2>String Operations</h2>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    Sentence: <input type="text" name="sentence"><br>
    Word: <input type="text" name="word"><br>
    Position: <input type="text" name="position"><br>
    Number of Characters: <input type="text" name="numChars"><br>
    <input type="submit" value="Submit">
</form>

<?php
// Displaying the results
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    echo "<p>Original Sentence: $sentence</p>";
    echo "<p>Result after deleting a small part: $result1</p>";
    echo "<p>Result after inserting the small string: $result2</p>";
    echo "<p>Result after replacing at specified position: $result3</p>";
}
?>
</body> </html>

Q2]
A]
import pandas as pd

1. Creating a dataframe with columns name, age, and percentage

data = {'name': ['John', 'Jane', 'Bob', 'Alice', 'Charlie', 'David', 'Eva', 'Frank', 'Grace', 'Henry'],
'age': [25, 22, 30, 28, 35, 40, 26, 32, 29, 27],
'percentage': [80.5, 75.2, 92.0, 88.5, 78.9, 95.3, 81.7, 89.6, 93.2, 87.4]}

df = pd.DataFrame(data)

2. Printing information about the dataframe

print("DataFrame:")
print(df)

print("\nDataFrame Information:")
print("Shape:", df.shape)
print("Number of Rows-Columns:", df.shape[0], "-", df.shape[1])
print("Data Types:")
print(df.dtypes)
print("Feature Names:")
print(df.columns)
print("Description:")
print(df.describe())

3. Adding 5 rows with duplicate values and missing values

df = pd.concat([df, df.head(5)], ignore_index=True)

Adding a column 'remarks' with empty values

df['remarks'] = ""

Displaying the updated data

print("\nUpdated DataFrame:")
print(df)