-
Notifications
You must be signed in to change notification settings - Fork 6
/
Test - Basic syntax, conditional statements and loops
94 lines (80 loc) · 2.22 KB
/
Test - Basic syntax, conditional statements and loops
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
1. Which of the following is the correct syntax for a Python comment?
a) // This is a comment
b) # This is a comment
c) /* This is a comment */
d) ** This is a comment **
2. What is the output of the following code snippet?
x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is less than or equal to 5")
a) x is greater than 5
b) x is less than or equal to 5
c) x
d) The code will produce a syntax error.
3. Which of the following is the correct way to define a Python function?
a) function_name(argument1, argument2):
b) def function_name(argument1, argument2):
c) function_name = def(argument1, argument2)
d) def = function_name(argument1, argument2)
4.What is the output of the following code snippet?
i = 0
while i < 5:
print(i)
i += 1
a) 0 1 2 3 4
b) 1 2 3 4 5
c) 0 1 2 3
d) 1 2 3 4
5.Which of the following is the correct way to declare a list in Python?
a) list_name = [value1, value2, value3]
b) list_name = {value1, value2, value3}
c) list_name = (value1, value2, value3)
d) list_name = {value1: value2, value3}
6.What is the output of the following code snippet?
for i in range(5):
if i == 2:
break
print(i)
a) 0 1 2 3 4
b) 1 2
c) 0 1
d) 0 1 3 4
7.Which of the following is the correct way to define a Python dictionary?
a) dict_name = {key1, key2, key3: value1, value2, value3}
b) dict_name = {key1: value1, key2: value2, key3: value3}
c) dict_name = [key1, key2, key3: value1, value2, value3]
d) dict_name = (key1, key2, key3: value1, value2, value3)
8.What is the output of the following code snippet?
x = 5
y = 10
if x > y:
print("x is greater than y")
elif x == y:
print("x is equal to y")
else:
print("x is less than y")
a) x is greater than y
b) x is equal to y
c) x is less than y
d) The code will produce a syntax error.
9.What is the output of the following code snippet?
i = 0
while i < 5:
print(i)
i += 2
a) 0 1 2 3 4
b) 0 2 4
c) 1 3 5
d) 2 4 6
Here are the correct answers to the Python test:
1 - b) # This is a comment
2 - a) x is greater than 5
3 - b) def function_name(argument1, argument2):
4 - a) 0 1 2 3 4
5 - a) list_name = [value1, value2, value3]
6 - c) 0 1
7 - b) dict_name = {key1: value1, key2: value2, key3: value3}
8 - c) x is less than y
9 - b) 0 2 4