Len Count
Len Count
What role
does each type play in a computer's functioning?
Answer: System software (e.g., operating system) and application software (e.g., word
processor) are necessary. System software manages computer resources, while
application software performs specific tasks.
Answer: In Python, dictionaries cannot have duplicate keys. If you try to create a
dictionary with duplicate keys, the last key-value pair will overwrite the previous ones.
Answer: len() returns the total number of elements in a list, while count() returns the
number of occurrences of a specific element in a list.
Answer: Memory stores data and program instructions. Computers work with two types
of memory: primary memory (RAM) and secondary memory (hard disk, SSD, etc.).
5. Why foreign keys are allowed to have NULL values? Explain with an example.
Answer: Foreign keys can have NULL values to indicate that the relationship with the
referenced table is not applicable or unknown. For example, a customer order may not
have a salesperson assigned (NULL foreign key).
7. Differentiate between primary key and Foreign key with an example of each.
Answer: Primary key uniquely identifies a record in a table, while a foreign key
references the primary key of another table. Example: In a customers table, customer_id
is the primary key, and in an orders table, customer_id is a foreign key referencing the
customers table.
8. Differentiate between CHAR and VARCHAR data type.
Answer: clear() removes all items from a dictionary, while del deletes the entire
dictionary.
Answer: A list is a collection of items that can be of different data types, while a string is a
sequence of characters.
Answer: Machine learning is a subset of AI that enables systems to learn from data and
improve their performance. Applications include image recognition, natural language
processing, recommendation systems, and more.
Answer: extend() adds multiple elements to a list, while append() adds a single
element to a list.
13. How can you eliminate duplicate records in a table with select query?
Answer: The precedence of operators determines the order in which operators are
evaluated in an expression.
18. Write the full forms of these: (i) IaaS, (ii) PaaS, (iii) SaaS, (iv) P2P
20. What is the difference between interactive mode and script mode in Python?
Answer: Interactive mode is a prompt-based interface for executing Python code, while
script mode involves executing a Python script file.
Answer: DROP deletes a table or database, while DELETE deletes specific rows from a
table.
Answer: The IS operator is used to test for null or not null values, while the LIKE
operator is used for pattern matching.
23. What is the significance of the DISTINCT clause? Explain it with an example.
Answer: The DISTINCT clause is used to remove duplicate rows from a result set.
Example: SELECT DISTINCT department FROM employees; returns a list of unique
departments.
Answer: AI is used in video games for tasks such as pathfinding, decision-making, and
adaptive difficulty adjustment, creating a more immersive and engaging experience.
Answer: The output will be: Final List: [123, 'xyz', 'zara', 2009, 'abc']
26. Differentiate between primary key and Foreign key with an example of each.
28. What will be the output of the following code: Lst=[10,50,20,30,40] print(Lst[::-
2])
iii. Big Data: Storage, processing, and analysis of large datasets for insights and decision-
making.
30. What is the difference between a literal and an identifier? Give 2 examples of
both.
Examples:
Literals: 5, "hello"
Identifiers: x, my_function
31. Write a program to read elements of a list and do the following: a) The
program should ask for the position of the element to be deleted from the list.
Write a function to delete the element at the desired position in the list. b) The
program should ask for the value of the element to be deleted from the list. Write
function to delete the element of this value from the list.
Answer:
del lst[pos]
else:
print("Invalid position")
if val in lst:
lst.remove(val)
else:
my_list = [1, 2, 3, 4, 5]
delete_by_position(my_list, pos)
delete_by_value(my_list, val)
33. Write a Python program to find the maximum and minimum values in a list.
Answer:
max_val = max(my_list)
min_val = min(my_list)
Answer: The split() function is used to split a string into a list of substrings based on a
specified separator.
35. Write a Python program to draw a graph with a suitable label in the X axis and
Y axis and a title.
Answer:
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.title('Line Graph')
plt.show()
36. What is the difference between break and continue statements in Python?
Answer: The break statement exits the loop, while the continue statement skips the
current iteration and continues with the next iteration.
37. Write a Python program to find the factorial of a number using recursion.
Answer:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
result = factorial(num)
Answer: The join() function is used to concatenate a list of strings into a single string.
39. Write a Python program to find the sum of digits of a number.
Answer:
def sum_of_digits(n):
sum = 0
while n > 0:
sum += n % 10
n //= 10
return sum
result = sum_of_digits(num)
Answer: The is operator checks for object identity, while the == operator checks for
value equality.
Answer:
import pandas as pd
df={"Technology":["Programming","Robotics","3DPrinting"],"Time(in months)":[4,4,3]}
df= pd.DataFrame(df)
print(df)
Corrections:
• Pd should be pd (lowercase)
• dataframe should be DataFrame (capitalized)
2. Complete the given Python code to get the required output as: Rajasthan
Answer:
import pandas as pd
NP = pd.Series(di)
print(NP['Sariska'])
Answer:
import pandas as pd
rollno=[1,2,3,4,5,6,7]
p=pd.Series(rollno) #Statement 1
print(p.head(3)) #Statement 2
4. Consider two objects L and S. L is a list whereas S is a Series. Both have values
20, 40,90, 110. What will be the output of the following two statements considering
that the above objects have been created already.
Answer:
5. Mr. Harry wants to draw a line chart using a list of elements named LIST.
Complete the code to perform the following operations:
Answer:
LIST=[10,20,30,40,50,60]
PLINE.plot(LIST) #Statement 1
PLINE.show()
Answer:
stock = pd.DataFrame(stationary)
# b. Add a column called ‘discount’ with the following data: [15, 20, 30, 25]
Answer: Single Row Functions operate on a single row of data and return a single value,
whereas Multi Row Functions operate on multiple rows of data and return a single value.
8. Write a program to create the series that stores the term marks of 10 students.
Find the highest and lowest three marks scored by students.
Answer:
import pandas as pd
marks = pd.Series([85, 90, 78, 92, 88, 76, 95, 89, 84, 91])
9. Write a program to create a series from list marks and taking index values from
list roll no. Show all elements that are above 80 marks.
Answer:
import pandas as pd
roll_no = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
marks = [85, 90, 78, 92, 88, 76, 95, 89, 84, 91]
Answer:
import matplotlib.pyplot as plt
plt.plot(B, A)
plt.xlabel("Index")
plt.ylabel("Value")
plt.title("Line Chart")
plt.show()
11. Write Python code to create the following DataFrame df1 using Python Pandas.
Answer:
import pandas as pd
df1 = pd.DataFrame(data)
print(df1)
12. Consider a given Series, D1: Write a program in Python Pandas to create the
series.
Answer:
import pandas as pd
print(D1)
13. Consider the decimal number x with value 54567.8577. Write commands in
SQL to:
Answer:
14. Based on the SQL table EMPL, write suitable queries for the following:
Answer:
Answer:
import pandas as pd
df = pd.DataFrame(data)
print(df)
16. Poonam wants to display first 3 elements from series S.
Answer:
import pandas as pd
# a. Rewrite the above program with necessary changes to help her get the desired
output.
print(S.iloc[:3])
# b. Write the statement to display the values which are greater than equal to 30.
# c. Write the statement to change the index name of the Series as "My Index".
print(S)
Answer:
CALORIE INTEGER
);
Answer:
import pandas as pd
# ii. Add a new genre of type ‘Folk Tale' having code as “FT” and 600 number of copies.
19. Sunita is working as DBA in Infosys, help her by writing answers of following
queries
Answer;
-- c. Write a query to display the details all those employees who joined in the
month of May.
-- d. Write a query to count total number of employees who joined in the year
2022.
20. Write the output of the given statement(s), based on the given DataFrame
named "df":
Answer:
# a. print(df.loc[:1])
# print(df.loc[2:,["Name","Married"]])
# c. df.weight[1]
# ans :123
# Output: 123
# d. print(df.age)
# ANS 15,20,18
Answer:
-- iv. To remove all the probable leading spaces from the column user_id of the table
named user.
22. Write a program to plot a bar graph and show the population of 6 years.
Answer:
plt.bar(year, population)
plt.xlabel("Year")
plt.ylabel("Population")
plt.title("Population of 6 Years")
plt.show()
23. HR Department of ABC Tech has created a dataframe ‘df1’ to store data about
name, salaries and bonus paid to their employees.
Answer:
import pandas as pd
print(df1[["Sal", "Bonus"]])
print(df1.tail(1))
# iii. Add a new column named ‘Email’ with NULL value for all rows.
df1["Email"] = None
import pandas as pd
print(df1.iloc[-3:])
24. Write a Pyhton program to draw a line with a suitable label in the X axis and Y
axis and a title.
Answer:
x = [1, 2, 3, 4, 5]
plt.plot(x, y)
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.title("Line Graph")
plt.show()
25. Write a code to draw the following bar graph representing the number of
students in each class:.
Answer:
classes = ["Class 1", "Class 2", "Class 3", "Class 4", "Class 5"]
plt.bar(classes, students)
plt.xlabel("Class")
plt.ylabel("Number of Students")
plt.show()
Answer:
scores = [10, 15, 10, 10, 10, 15, 20, 20, 20, 20, 20, 25, 25]
plt.xlabel("Score")
plt.ylabel("Frequency")
plt.title("Frequency of Score")
plt.show()
27. Mr Ramesh wrote a Query to find the sum of bonus earned by the employees of
WEST zone:
Answer:
Answer:
import pandas as pd
x = [[100, 200, 300], [10, 20]]
df = pd.DataFrame(x)
print(df)
print(df)
# ii. Write the syntax for displaying size and shape of the above dataframe.
print(df.size)
print(df.shape)
29. Based on the SQL table STUDENT, write suitable queries for the following:
Answer:
30. Predict the output of the following queries based on the table PURCHASE given
above:
Answer:
Answer:
INSERT INTO exam (RegNo, Name, Subject, Marks) VALUES (6, 'Khushi', 'CS', 85);
-- 3. To remove the records of those students whose marks are less than 30 .
DELETE FROM exam WHERE Marks < 30;
32. Consider the two objects s1 and s2. s1 is a list whereas s2 is a Series. Both have
values 100, 200, 300, 400, 500.
Answer:
# a. print(s1 * 2)
# b. print(s2 * 2)
# Output: 0 200
1 400
2 600
3 800
4 1000
dtype: int64
33. Given the dataset for Employee:
Answer:
import pandas as pd
df = pd.DataFrame(data)
print(df)
plt.hist(df['Age'], bins=10)
plt.xlabel("Age")
plt.ylabel("Frequency")
plt.show()