Which function is used to take user input in Python? a) scanf() b) cin c) input() d) read()
Every question in this chapter, answered and explained — step-by-step solutions drawn live from the chapter library across 1 question section.
Which function is used to take user input in Python? a) scanf() b) cin c) input() d) read()
What will be the output of the following code? a, b = 10, 3 print(a // b) a) 3.33 b) 3 c) 4 d) Error
What is the purpose of the else clause in a loop? a) It runs when the loop finishes without encountering break. b) It runs when the loop finishes with break. c) It executes before the loop. d) It has no effect.
What is the output of 2 ** 3 ** 2? a) 64 b) 512 c) 9 d) None of the above
What will be the output of the following code? num = -5 if num > 0: print("Positive") elif num == 0: print("Zero") else: print("Negative") a) Positive b) Zero c) Negative d) None of the above
Which of the following is not a valid conditional statement in Python? a) if condition: b) elif condition: c) else condition: d) else:
How many times will the loop run? for i in range(2, 10, 2): print(i) a) 3 b) 4 c) 5 d) 8
What will be the output of the following while loop? x = 5 while x > 0: print(x, end=" ") x -= 1 a) 5 4 3 2 1 b) 5 4 3 2 c) 4 3 2 1 d) None of these
What will be the output of this code? fruits = ["apple", "banana", "cherry"] print(fruits[-1]) a) apple b) banana c) cherry d) Error
How do you add a new key-value pair to a dictionary? a) dict.add("key", "value") b) dict["key"] = "value" c) dict.append("key", "value") d) dict.insert("key", "value")
What does the following code return? text = "hello" print(text.upper()) a) hello b) HELLO c) Hello d) Error
What will be the output of the following code? text = "Python" print(len(text)) a) 5 b) 6 c) 7 d) Error
What will be the output of abs(-10)? a) -10 b) 1 c) 0 d) None of above
What does math.sqrt(16) return? a) 4.0 b) 4 c) 8 d) None of these
What will be the output of this program? for i in range(3): for j in range(2): print(i, j)
What happens when break is used inside a loop? a) It skips the current iteration and continues the loop. b) It terminates the loop immediately. c) It raises an error. d) It moves to the next loop.
What will be the output of the following code? for i in range(5): if i == 3: continue print(i, end=" ") a) 0 1 2 b) 0 1 2 4 c) 0 1 2 3 4 d) None of the above