Q. 1) Write a PHP script to create student.xml file which contains student roll no, name, address, college
and course. Print students detail of specific course in tabular format after accepting course as input.
[Marks 15]
<?php
// Create student.xml file with student details
$students = array(
array('rollno' => '101', 'name' => 'John', 'address' => '123 Main St', 'college' => 'ABC College', 'course' => 'Engineering'),
array('rollno' => '102', 'name' => 'Alice', 'address' => '456 Elm St', 'college' => 'XYZ College', 'course' => 'Medicine'),
array('rollno' => '103', 'name' => 'Bob', 'address' => '789 Oak St', 'college' => 'PQR College', 'course' => 'Law'),
array('rollno' => '104', 'name' => 'Eve', 'address' => '101 Pine St', 'college' => 'LMN College', 'course' => 'Engineering'),
array('rollno' => '105', 'name' => 'Mary', 'address' => '202 Cedar St', 'college' => 'UVW College', 'course' => 'Medicine')
);
$doc = new DOMDocument();
$doc->formatOutput = true;
$root = $doc->createElement('students');
$doc->appendChild($root);
foreach ($students as $student) {
$studentNode = $doc->createElement('student');
foreach ($student as $key => $value) {
$node = $doc->createElement($key, $value);
$studentNode->appendChild($node);
}
$root->appendChild($studentNode);
}
$doc->save('student.xml');
echo "student.xml file created successfully!<br><br>";
// Accept course input
$course = isset($_POST['course']) ? $_POST['course'] : '';
if (!empty($course)) {
$xml = simplexml_load_file('student.xml');
// Filter students by course
$filteredStudents = $xml->xpath("//student[course='$course']");
if (count($filteredStudents) > 0) {
echo "Students of $course course:<br><br>";
echo "<table border='1'><tr><th>Roll No</th><th>Name</th><th>Address</th><th>College</th><th>Course</th></tr>";
foreach ($filteredStudents as $student) {
echo "<tr>";
echo "<td>{$student->rollno}</td>";
echo "<td>{$student->name}</td>";
echo "<td>{$student->address}</td>";
echo "<td>{$student->college}</td>";
echo "<td>{$student->course}</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "No students found for $course course.";
}
} else {
echo "Please enter a course.";
}
?>
<!-- HTML form to accept course input -->
<form method="post" action="">
<label for="course">Enter course:</label>
<input type="text" name="course" id="course">
<input type="submit" value="Submit">
</form>
Q. 2) Consider the following dataset :
Write a Python script for the following :
i. Read the dataset and perform data cleaning operations on it.
ii. ii. Find the total views, total likes, total dislikes and comment count.
import pandas as pd
Read the dataset
df = pd.read_csv('INvideos.csv')
Data cleaning operations (if needed)
Calculate total views, likes, dislikes, and comment count
total_views = df['views'].sum()
total_likes = df['likes'].sum()
total_dislikes = df['dislikes'].sum()
total_comments = df['comment_count'].sum()
print("Total Views:", total_views)
print("Total Likes:", total_likes)
print("Total Dislikes:", total_dislikes)
print("Total Comments:", total_comments)