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.
This CBSE Class 8 ICT practice quiz has 20 multiple-choice questions on Simple Python Programs, and 20 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 20 questions, freeSample questions
What will be the output of the following code? print('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?
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)
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))
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))
Show answer
Answer: A. 5
The function add() takes two arguments, adds them, and returns the result. Therefore, add(2, 3) returns 5.
More questions in this quiz
Answers and explanations are in the full quiz.
- Which data type is used to define a number in Python?
- What will the following code print? x = 5 print(x * 2)
- What does the following code return? len('Python')
- Which of the following is a list in Python?
- What will the following code output? if 3 > 2: print('True') else: print('False')
- What is the purpose of the 'def' keyword in Python?
- What does the following code check? if x in [1, 2, 3]:
- What will the following code output? for i in range(3): print(i)
- What does the following code return? max([1, 2, 3])
- What is the result of the expression '3 + 2 * 2'?
- How can you create a comment in Python?
- What will the function call 'sorted([3, 1, 2])' return?
- What is the output of this code? for i in range(4): if i == 2: break print(i)
- Which of the following is a correct way to handle an exception in Python?
- What will be the output of the following code? def square(x): return x**2 print(square(4))
More quizzes
Browse all Programming Basics quizzes