0% found this document useful (0 votes)
28 views7 pages

Mock1 Code

The document contains a series of programming questions and their correct answers related to Python, covering topics such as arithmetic operations, list and tuple manipulations, and dictionary comparisons. Each question includes a solution explaining the reasoning behind the correct answer. Additionally, there are brief explanations for two programming concepts: checking for half palindromes and comparing elements with their neighbors in an array.

Uploaded by

vijay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views7 pages

Mock1 Code

The document contains a series of programming questions and their correct answers related to Python, covering topics such as arithmetic operations, list and tuple manipulations, and dictionary comparisons. Each question includes a solution explaining the reasoning behind the correct answer. Additionally, there are brief explanations for two programming concepts: checking for half palindromes and comparing elements with their neighbors in an array.

Uploaded by

vijay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1. What is the output of print(2 * 3 ** 3 * 4)?

A. 216​
B. 864​
C. 316​
D. 1664

✅ Correct Answer: B. 216​


Solution: 3 ** 3 = 27, then 2 * 27 * 4 = 216

2. What is the output of print(10 - 4 * 2)?

A. 10​
B. -3​
C. 12​
D. 2

✅ Correct Answer: D. 2​
Solution: 4 * 2 = 8, then 10 - 8 = 2

3. What is the output of the expression print(-18 // 4)?

A. -5​
B. -4​
C. 4​
D. 5

✅ Correct Answer: A. -5​


Solution: Floor division of -18 by 4 gives -5 (since it rounds towards minus infinity)

4. What is the output of the following code?

sampleList = [10, 20, 30, 40]


del sampleList[0:6]
print(sampleList)

A. list index out of range​


B. []​
C. [10, 20]​
D. None of these

✅ Correct Answer: B. []​


Solution: del with slice removes all elements even if end index is beyond list size.

5. What is the output of the following code?

my_list = ["Hello", "Python"]


print("-".join(my_list))

A. Hello-Python​
B. HelloPytho-n​
C. HelloPython-​
D. -HelloPython

✅ Correct Answer: A. Hello-Python​


Solution: join() places - between strings in the list.

6. What is the output of the following code?

aTuple = (100, 200, 300, 400, 500)


aTuple[1] = 800
print(aTuple)

A. (100, 800, 200, 300, 400, 500)​


B. (800, 100, 200, 300, 400, 500)​
C. TypeError​
D. None of the above

✅ Correct Answer: C. TypeError​


Solution: Tuples are immutable; you can't assign to their elements.



7. What is the output of the following code?

aTuple = "Yellow", 20, "Red"


a, b, c = aTuple
print(a)

A. Red​
B. Yellow​
C. (‘Yellow’, 20, ‘Red’)​
D. TypeError

✅ Correct Answer: B. Yellow​


Solution: Tuple unpacking assigns a = "Yellow".

8. A Python tuple can also be created without using parentheses

A. False​
B. True

✅ Correct Answer: B. True​


Solution: Tuple syntax without parentheses is allowed: x = 1, 2

9. What is the output of the following code?

sampleDict = dict([
('first', 1),
('second', 2),
('third', 3)
])
print(sampleDict)

A. [(‘first’, 100), (‘second’, 200), (‘third’, 300)]​


B. SyntaxError: invalid syntax​
C. {'first': 1, 'second': 2, 'third': 3}​
D. None of these

✅ Correct Answer: C. {'first': 1, 'second': 2, 'third': 3}​


Solution: dict() can accept a list of tuples as key-value pairs.

10. What is the output of the following code?


dict1 = {"key1":1, "key2":2}
dict2 = {"key2":2, "key1":1}
print(dict1 == dict2)

A. True​
B. False

✅ Correct Answer: A. True​


Solution: Dictionary equality is order-independent, values are the same.

11.Half Palindrome

Solution ​
Explanation : ​

1.Splits the string into two equal halves.​
2.Checks if both halves are palindromes using a custom function.​
3.If both are palindromes → prints "yes", else → prints "no".​


12.Compete With Neighbour ​

Solution ​

Explanation : ​
We check how many elements in the array are greater than their neighbors:

●​ First element: compare with second.​

●​ Last element: compare with second last.​

●​ Middle elements: compare with both left and right neighbors.​


If an element is greater than its neighbor(s), we count it.

You might also like