Completed
Python & SQL Challenge
Questions From This Challenge
Q1output1 mark
What will be the output of the following Python code?
def calculate(a, b=2):
return a + b * 3
print(calculate(4))
print(calculate(4, 1))
Correct output:
10
7Q2mcq1 mark
Consider the following SQL statements: CREATE TABLE Student ( RollNo INT PRIMARY KEY, Name VARCHAR(20), Marks INT ); INSERT INTO Student VALUES (101, 'A', 35); INSERT INTO Student VALUES (102, 'B', 48); INSERT INTO Student VALUES (103, 'C', 62); UPDATE Student SET Marks = Marks + 5 WHERE Marks < 50; DELETE FROM Student WHERE Marks BETWEEN 40 AND 50; Which students remain in the table?
RollNo 101 only
RollNo 102 only ✓
RollNo 101 and 103
RollNo 103 only
Q3output1 mark
What will be the output of the following Python code?
n = 2
total = 0
while n <= 15:
if n % 3 == 0:
n = n + 4
continue
total = total + n
n = n + 3
print(total)
Correct output:
40Q4mcq1 mark
A table Employee is defined as: CREATE TABLE Employee ( EmpID INT PRIMARY KEY, Name VARCHAR(25) NOT NULL, Salary FLOAT, Email VARCHAR(40) UNIQUE ); Which pair of records can be inserted successfully?
(101, 'Amit', 25000, 'a@x.com') and (102, 'Ravi', 30000, 'b@x.com') ✓
(101, 'Amit', 25000, 'a@x.com') and (101, 'Ravi', 30000, 'b@x.com')
(101, NULL, 25000, 'a@x.com') and (102, 'Ravi', 30000, 'b@x.com')
(101, 'Amit', 25000, 'a@x.com') and (102, 'Ravi', 30000, 'a@x.com')
Q5output1 mark
What will be the output of the following Python code?
x = 10
for i in range(2, 8):
if i % 3 == 0:
x = x // 2
elif i % 2 == 0:
x = x + i
else:
x = x - 1
print(x)
Correct output:
3Q6mcq1 mark
Consider the following table: Student(RollNo, Name, Marks, City) Which query correctly retrieves students whose City is NULL?
SELECT * FROM Student WHERE City = NULL;
SELECT * FROM Student WHERE City IS NULL; ✓
SELECT * FROM Student WHERE City == NULL;
SELECT * FROM Student WHERE City IN (NULL);
Q7output1 mark
What will be the output of the following Python code?
def test(x):
if x > 10:
return x - 3
return x + 3
a = test(8)
b = test(a)
print(a, b)
Correct output:
11 8Q8mcq1 mark
Consider the following SQL query: SELECT * FROM Student WHERE Marks >= 40 AND Marks <= 60 OR Marks = 90; For which set of marks will a record be selected?
35, 40, 60, 90
40, 50, 60, 90 ✓
40, 60, 70, 90
35, 50, 60, 90
Q9output1 mark
What will be the output of the following Python code?
L = [4, 7, 2, 9] L[1] = L[0] + L[2] L.append(L[-1] - L[1]) L.pop(0) print(L)
Correct output:
[6, 9, 3]Q10mcq1 mark
Consider the following table: Student(RollNo, Name) Which condition selects names having exactly two characters before the letter 'a'?
Name LIKE '__a%' ✓
Name LIKE '%__a'
Name LIKE '__%a'
Name LIKE '%a__%'
Q11mcq1 mark
Consider the following SQL statements: CREATE TABLE Employee ( EmpID INT PRIMARY KEY, Name VARCHAR(20), Salary FLOAT ); ALTER TABLE Employee ADD Department VARCHAR(20); ALTER TABLE Employee DROP Salary; Which statement about the final table structure is correct?
EmpID, Name and Department are present ✓
EmpID and Salary are present
Name, Salary and Department are present
Only EmpID and Department are present
Q12output1 mark
What will be the output of the following Python code?
try:
x = int("12")
y = 10 // 0
print(x + y)
except ValueError:
print("Value")
except ZeroDivisionError:
print("Zero")
Correct output:
ZeroQ13mcq1 mark
Consider the following table: Student(RollNo, Marks) 101 38 102 52 103 68 104 42 The following statements are executed in order: UPDATE Student SET Marks = Marks + 5 WHERE Marks < 50; DELETE FROM Student WHERE Marks BETWEEN 40 AND 50; Which RollNo values remain?
101, 102, 103
102, 103 ✓
101, 103, 104
103 only
Q14output1 mark
What will be the output of the following Python code?
stack = [10, 20, 30] stack.append(40) stack.pop() stack.append(stack[-1] + 5) print(stack)
Correct output:
[10, 20, 35]Q15mcq1 mark
Consider the following SQL query: SELECT * FROM Student WHERE Marks IN (35, 50, 75) AND City IS NOT NULL; Which student records can be selected?
Records with Marks 35, 50 or 75 and a non-NULL City ✓
Records with Marks between 35 and 75 and a non-NULL City
Records with Marks 35, 50 or 75 including NULL City
Records with Marks greater than 35 and less than 75 with a non-NULL City