Unit 4: Unit 4: Control Structures in Python — Mcqs
10th Class Computer Science · Unit 4: Unit 4: Control Structures in Python
0 of 0 answered
0 correct
Decision Making
1.Which Python statement is used to make a decision based on a condition?
2.What happens if indentation is not correct in an if statement?
3.Which of the following allows executing one block if a condition is true and another if it is false?
4.What is nesting in Python decision-making structures?
5.What does the following code print?
temperature=35
if temperature>30:
print("It's a hot day")
6.What is the output of this nested condition?
weather="rainy"
temperature=10
if weather=="rainy":
if temperature<15:
print("Wear a raincoat")
else:
print("Take an umbrella")
else:
print("Enjoy your day!")
7.Which of the following is true about if-else statements?
Looping Constructs
8.What is a looping structure in programming?
9.Which of the following is a type of loop in Python?
10.What happens when the condition in a while loop becomes false?
11.What is the purpose of the range() function in Python?
12.Which of the following correctly uses the end statement in Python?
13.What is a nested loop?
14.Which loop is best for iterating over a known sequence like a list?
15.What is the output of the following while loop?
number=1
while number<4:
print(number)
number+=1
16.Output of the following code:
num=1
odd_count=0
while num<5:
if num%2==0:
print(f"Even:{num}")
else:
odd_count+=1
num+=1
print("Total odd numbers:",odd_count)
- a Even: 2 Even: 4 Total odd numbers: 3
- b Even: 2 Even: 4 Total odd numbers: 2
- c Even: 1 Even: 3 Total odd numbers: 2
- d Even: 1 Even: 2 Total odd numbers: 3
17.Output of the following code:
friends=["Arshad","Ayaan","Areeda"]
for friend in friends:
print("Hello",friend)
18.Output of the following code:
for i in range(5):
print(i)
19.Output of the following code:
for i in range(1,6):
print(i,end="")
20.Output of the following code:
for i in range(2):
for j in range(3):
print(f"i={i},j={j}")
21.Output of the following code:
n=3
for i in range(1,n+1):
for j in range(i):
print("*",end="")
print()
Libraries in Python
22.What are Python libraries?
23.Why should you import libraries in Python?
24.Which library is used to generate random numbers in Python?
25.What does the following code do?
import random
number=random.randint(1,10)
print(number)
26.Which library is useful for handling dates and times in Python?
27.What is the purpose of the statistics library in Python?
28.Why should you only import what you need in Python?
29.Where can you find more information about Python libraries?
Lists in Python
30.What is a list in Python?
31.How do you create a list in Python?
32.Which of the following is a valid list?
33.How can you access the second item in a list fruits = ["Mango", "Apple", "Banana"]?
34.How do you change the first element of a list to "Orange"?
35.Which method adds a new item to the end of a list?
36.What does the remove(item) method do in Python lists?
37.What is the result of sorting a list [34, 12, 89, 5, 23] using sort()?
38.What does the reverse() method do in Python lists?
39.What is the output of the following code?
fruits=["Mango","Apple","Banana"]
fruits[0]="Orange"
fruits.append("Pineapple")
40.What is the output of the following code?
students=["Ahmed","Sara","Ali","Hina","Sara"]
students.remove("Sara")
print(students)
41.What is the output of the following code?
fruits=["Apple","Banana","Orange","Mango"]
fruits.reverse()
print(fruits)
Testing and Debugging in Python
42.What is the main purpose of testing in Python programming?
43.Which type of testing checks individual parts of the code, like functions or classes, in isolation?
44.Which type of testing ensures that new changes do not break existing functionality?
45.Which testing validates that the software behaves as expected from the user's perspective?
46.What is debugging in Python?
47.Which of the following is a common technique for debugging?
48.Which Python tool allows you to step through code and inspect variables during execution?
49.How can error messages help in debugging?
50.What are the output of the following code?
x=5
y=0
print(x/y)
51.Which of the following is NOT a type of testing?