OneCompiler

Hslip15

106

Q1]

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>String Operations</title> </head> <body> <form method="post" action="process_string.php"> <label for="inputString">Enter a String:</label> <input type="text" name="inputString" required>
<input type="submit" value="Submit">
</form> </body> </html> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>String Operations Result</title> </head> <body> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $inputString = $_POST["inputString"]; // a. To select first 5 words from the string $first5Words = implode(' ', array_slice(explode(' ', $inputString), 0, 5)); echo "<p>a. First 5 words: $first5Words</p>"; // b. Convert the given string to lowercase and then to Title case $lowercaseTitlecase = ucwords(strtolower($inputString)); echo "<p>b. Lowercase and Title case: $lowercaseTitlecase</p>"; // c. Pad the given string with “*” from left and right both the sides $paddedString = str_pad($inputString, strlen($inputString) + 2, "*", STR_PAD_BOTH); echo "<p>c. Padded String: $paddedString</p>"; // d. Remove the leading whitespaces from the given string $trimmedString = ltrim($inputString); echo "<p>d. String after removing leading whitespaces: $trimmedString</p>"; // e. Find the reverse of given string $reverseString = strrev($inputString); echo "<p>e. Reverse of the String: $reverseString</p>"; } ?> </body> </html> Q2] a] import numpy as np import matplotlib.pyplot as plt

Generate a random array of 50 integers

random_array = np.random.randint(1, 100, 50)

Line chart

plt.figure(figsize=(12, 5))
plt.subplot(2, 2, 1)
plt.plot(random_array, label='Random Array', color='blue')
plt.title('Line Chart')
plt.xlabel('Index')
plt.ylabel('Value')
plt.legend()

Scatter plot

plt.subplot(2, 2, 2)
plt.scatter(range(1, 51), random_array, label='Random Array', color='green')
plt.title('Scatter Plot')
plt.xlabel('Index')
plt.ylabel('Value')
plt.legend()

Histogram

plt.subplot(2, 2, 3)
plt.hist(random_array, bins=10, color='orange', edgecolor='black')
plt.title('Histogram')
plt.xlabel('Value')
plt.ylabel('Frequency')

Box plot

plt.subplot(2, 2, 4)
plt.boxplot(random_array, vert=False, patch_artist=True)
plt.title('Box Plot')
plt.xlabel('Value')

plt.tight_layout()
plt.show()

B]
import matplotlib.pyplot as plt

Create two lists representing subject names and marks

subject_names = ['Math', 'Science', 'English', 'History', 'Geography']
marks_obtained = [90, 85, 88, 92, 78]

Display the data in a pie chart

plt.figure(figsize=(8, 8))
plt.pie(marks_obtained, labels=subject_names, autopct='%1.1f%%', startangle=90, colors=['#ff9999', '#66b3ff', '#99ff99', '#ffcc99', '#c2c2f0'])
plt.title('Subject-wise Marks Distribution')
plt.show()