CODING CONTEST TEST -SOLUTION
Name: Saniya Manihar
Page -1
Section-A
A1-3, A-4, A3-1, A4-2, A5-5
Section B: True or False
1. False
2. False
3. True
4. True
5. True
Section C:
1. 1.array
2. int
3. or
4. tail
5. +
Q.1 What is a DataFrame in pandas? Give a real-life example of where it can be used
A DataFrame is like a table with rows and columns, similar to an Excel sheet. In real life, we can
use it to store student records like Name, Roll Number, Marks, and Grade.
Q.2 Explain the difference between if and elif in Python.
if used to check the first condition, if it’s true, that block runs.
Else Is used when we want to check another condition only if the first if condition was false
Q.3 Aggregate functions process array data and give one value as a result,
e.g., mean() (average), sum() (total).
Yes , Aggregate functions process array data and give one value as a result,
e.g., mean() (average), sum() (total).
Q.4 Why is type conversion important in Python? Give an example.
Type conversion is important in Python because it allows us to change data from one type to
another data type
e.g
age = 20
print(int(age) + 5
Name: Saniya Manihar
Page -2
Q.5 Use df.info() or df.head() to see the structure and first rows of a DataFrame.
import pandas as pd
data = {"Name": ["Saniya", "Siddiqui"], "Age": [22, 25]}
df = pd.DataFrame(data)
print(df.info())
print(df.head())
SECTION-E
Q.1 Create a NumPy array containing the values from 1 to 10. Write code to:
Calculate and print the mean (average) of the array.
Find and print the maximum and minimum values in the array.
import numpy as np
arr = np.array([1,2,3,4,5,6,7,8,9,10])
avg_value = arr.mean()
max_value = arr.max()
min_value = arr.min()
print("Array:", arr)
print("Mean (Average):", avg_value)
print("Maximum:", max_value)
print("Minimum:", min_value
)
Name: Saniya Manihar
Page -3
Q2. (4 marks) Write a Python code that takes an integer input from the user, and checks if the
number is even or odd using if-else. Print "Even" or "Odd" as output.
num = int(input("Enter an integer: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Name: Saniya Manihar
Page -4
Q.3 Create a pandas DataFrame with columns "Product" Rice, Sugar, Oil), and "Price" 50, 40,
100 . Display the first row and use pandas to find the average price
import pandas as pd
data = {
"Product": ["Rice", "Sugar", "Oil"],
"Price": [50, 40, 100]
}
df = pd.DataFrame(data)
print("First Row:")
print(df.head(1))
avg_price = df["Price"].mean()
print("\nAverage Price:", avg_price)
Name: Saniya Manihar
Page -5
Q.4 Given a NumPy array arr = np.array([3, 8, 1, 6, 0, 7 , write code to count how many
elements are greater than 4.
import numpy as np
arr = np.array([3, 8, 1, 6, 0, 7])
count = np.sum(arr > 4)
print("Number of elements greater than 4:", count)
Name: Saniya Manihar
Page -6
Q.5 Write Python code to check if a given number is positive, negative, or zero using if-elif-else
statements. Print the result.
num = int(input("Enter a number: "))
if num > 0:
print("The number is Positive")
elif num < 0:
print("The number is Negative")
else:
print("The number is Zero")
Name: Saniya Manihar
Page -7