Simple Python Programs Quiz - CBSE Class 8 ICT
Free practice quiz: Simple Python Programs (CBSE Class 8 ICT). 20 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 20 questions freeSample questions
What will be the output of the following code? print('Hello, World!')
- Hello, World!
- Hello World!
- Hello,World!
- Hello World!,
Show answer
Answer: A. Hello, World!
The print function in Python outputs the string exactly as it is provided. Thus, the output will be 'Hello, World!' with the comma and space included.
What is the output of 5 // 2 in Python?
- 2
- 2.5
- 3
- 1
Show answer
Answer: A. 2
The // operator in Python performs floor division, which discards the decimal part. So, 5 // 2 results in 2.
What is the output of the following code? print(3 != 5)
- True
- False
- Error
- None
Show answer
Answer: A. True
The != operator checks if two values are not equal. Since 3 is not equal to 5, the output will be 'True'.
What will the following code print when run? x = [1, 2, 3] print(len(x))
- 2
- 3
- 1
- Error
Show answer
Answer: B. 3
The len() function returns the number of elements in the list x, which is 3.
What will the following program output? def add(a, b): return a + b print(add(2, 3))
- 5
- 6
- 2
- Error
Show answer
Answer: A. 5
The function add() takes two arguments, adds them, and returns the result. Therefore, add(2, 3) returns 5.