Python Control Structures
Python Control Structures - Important Points
31. | Which of the following statements is used to iterate over a range of numbers in Python? |
---|
A. for i in range(n):
B. for i in range(0, n):
C. for i in range(1, n+1):
D. All of the above
View Answer Discuss Work SpaceAnswer: option d
Explanation:
All of the above statements can be used to iterate over a range of numbers in Python, depending on the specific needs of the loop.
32. | Which of the following statements is used to check if a number is odd in Python? |
---|
A. num % 2 == 0
B. num % 2 == 1
C. num.is_odd()
D. num.odd()
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The % operator is used to find the remainder when dividing by 2, so if the remainder is 1, the number is odd.
33. | Which of the following statements is used to check if a number is positive in Python? |
---|
A. num > 0
B. num >= 0
C. num < 0
D. num <= 0
View Answer Discuss Work SpaceAnswer: option a
Explanation:
A number is considered positive if it is greater than 0.
34. | Which of the following statements is used to check if a number is a multiple of another number in Python? |
---|
A. num % multiple == 0
B. num / multiple == 0
C. num % multiple == 1
D. num / multiple == 1
View Answer Discuss Work SpaceAnswer: option a
Explanation:
If a number is a multiple of another number, the remainder when dividing by that number will be 0.
35. | Which of the following statements is used to repeat a sequence a certain number of times in Python? |
---|
A. for i in range(n):
B. while i < n:
C. repeat(n, sequence)
D. sequence * n
View Answer Discuss Work SpaceAnswer: option d
Explanation:
Multiplying a sequence by a number will repeat that sequence that number of times.