
Ctrl+Solve
Quiz
•
Computers
•
University
•
Practice Problem
•
Hard
Muhammed Nihal Noushad
Used 8+ times
FREE Resource
Enhance your content in a minute
25 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
def add_item(item, lst=[ ]):
lst.append(item)
return lst
print(add_item(1))
print(add_item(2))
print(add_item(3, [ ]))
print(add_item(4))
What is the output?
[1] [2] [3] [4]
[1] [1, 2] [3] [1, 2, 4]
[1] [2] [3] [4]
[1] [1, 2] [3] [4]
2.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A short snippet is displayed in a scrambled order. Which option shows the correct order for the code?
Scrambled Snippet:
printf("Result: %d", calculate(3));
int calculate(int n) {
return n > 0 ? n * calculate(n - 1) : 1;
}
Expected Output:
Result: 6
int calculate(int n) {
return n > 0 ? n * calculate(n - 1) : 1;
}
printf("Result: %d", calculate(3));
printf("Result: %d", calculate(3));
int calculate(int n) {
return n > 0 ? n * calculate(n - 1) : 1;
}
int calculate(int n);
printf("Result: %d", calculate(3));
int calculate(int n) {
return n > 0 ? n * calculate(n - 1) : 1;
}
int calculate(int n) {
return n > 0 ? n + calculate(n - 1) : 1;
}
printf("Result: %d", calculate(3));
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include<stdio.h>
void recurse() {
int arr[1000]; // Large stack allocation
recurse();
}
int main() {
recurse();
return 0;
}
What is the error?
No error, infinite recursion allowed
Stack overflow due to uncontrolled recursion
Compilation error due to large array
Undefined behavior
4.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
x = 0 or None or [ ] or { } or 42
print(x)
What will be printed?
0
None
[ ]
42
Answer explanation
• The or operator returns the first truthy value or the last falsy value if all are falsy.
• 0, None, [], {} are all falsy, so Python keeps evaluating.
• 42 is truthy, so it is returned.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
x = 10
def outer():
x = 5
def inner():
nonlocal x
x += 1
return x
return inner()
print(outer(), x)
What is the output?
6 10
6 6
UnboundLocalError
5 10
6.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A short snippet is displayed in a scrambled order. Which option shows the correct order for the code?
Scrambled Snippet:
printf("Value: %d", arr[2]);
arr[2] += modify(arr[1]);
int arr[ ] = {1, 2, 3, 4};
int modify(int x) {
return x * 2;
}
Expected Output:
Value: 7
int modify(int x) {
return x * 2;
}
int arr[ ] = {1, 2, 3, 4};
arr[2] += modify(arr[1]);
printf("Value: %d", arr[2]);
printf("Value: %d", arr[2]);
arr[2] += modify(arr[1]);
int arr[ ] = {1, 2, 3, 4};
int modify(int x) {
return x * 2;
}
int arr[ ] = {1, 2, 3, 4};
arr[2] += modify(arr[1]);
printf("Value: %d", arr[2]);
int modify(int x) {
return x * 2;
}
int modify(int x);
int arr[ ] = {1, 2, 3, 4};
arr[2] += modify(arr[1]);
printf("Value: %d", arr[2]);
int modify(int x) {
return x + 2;
}
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include<stdio.h>
#include<stdlib.h>
int* createNumber() {
int num = 42;
return #
}
int main() {
int* ptr = createNumber();
printf("%d", *ptr);
return 0;
}
What is the error?
No error, prints 42
Undefined behavior due to returning a local variable's address
Segmentation fault
Compilation error
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
20 questions
Review Quiz (Chapter 3&4)
Quiz
•
University
20 questions
ĐC CNTT_Chương 1
Quiz
•
University
20 questions
C Programming Unit-1 Test-2
Quiz
•
University
20 questions
Java Quiz 1
Quiz
•
University
20 questions
TEST1.PY
Quiz
•
10th Grade - University
20 questions
MESYUARAT KE-3 MYTECC ASSEMBLY: TOGETHER WE BIND
Quiz
•
University
20 questions
NANOTECNOLOGIA
Quiz
•
University
20 questions
Ôn tập phần 01 (20 câu đầu)
Quiz
•
10th Grade - University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
