menu

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

Discuss Work Space

Answer: 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()

Discuss Work Space

Answer: 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

Discuss Work Space

Answer: 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

Discuss Work Space

Answer: 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

Discuss Work Space

Answer: option d

Explanation:

Multiplying a sequence by a number will repeat that sequence that number of times.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now