0% found this document useful (0 votes)
22 views

CCE MCQ Test - Python Basics

Test paper in GTU

Uploaded by

dx2vqqzd64
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

CCE MCQ Test - Python Basics

Test paper in GTU

Uploaded by

dx2vqqzd64
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

CCE MCQ Test_Python Basics

Multiple-choice questions to test your knowledge of Python basics.

1. What is the correct file extension for Python files?

Mark only one oval.

a) .pt

b) .pyt

c) .py

d) .python

2. How do you insert comments in Python code?

Mark only one oval.

a) // This is a comment

b) # This is a comment

c) <!-- This is a comment -->

d) /* This is a comment */

3. Which of the following is used to define a block of code in Python?

Mark only one oval.

a) Curly braces {}

b) Parentheses ()

c) Indentation

d) Square brackets []

https://docs.google.com/forms/d/1Mu8vMR6fEs3acpTydHK8NhhYR_6HMPoJOzy5Ntd83Ts/printform 05/07/24, 9 06 AM
Page 1 of 8
:
4. How do you create a variable with the numeric value 5?

Mark only one oval.

a) x = int(5)

b) x = 5

c) int x = 5

d) Both a and b

5. Which operator is used to multiply numbers in Python?

Mark only one oval.

a) *

b) x

c) %

d) #

6. What is the output of the following code: print(2**3)?

Mark only one oval.

a) 5

b) 6

c) 8

d) 9

https://docs.google.com/forms/d/1Mu8vMR6fEs3acpTydHK8NhhYR_6HMPoJOzy5Ntd83Ts/printform 05/07/24, 9 06 AM
Page 2 of 8
:
7. How do you create a list in Python?

Mark only one oval.

a) myList = (1, 2, 3)

b) myList = [1, 2, 3]

c) myList = {1, 2, 3}

d) myList = <1, 2, 3>

8. How do you start a function in Python?

Mark only one oval.

a) function myFunc():

b) def myFunc():

c) create myFunc():

d) def myFunc[]:

9. Which of the following is the correct way to print a string in Python?

Mark only one oval.

a) echo "Hello, World!"

b) print("Hello, World!")

c) printf("Hello, World!")

d) cout << "Hello, World!";

https://docs.google.com/forms/d/1Mu8vMR6fEs3acpTydHK8NhhYR_6HMPoJOzy5Ntd83Ts/printform 05/07/24, 9 06 AM
Page 3 of 8
:
10. How do you check if a value is equal to another value in Python?

Mark only one oval.

a) a = b

b) a == b

c) a === b

d) a equal b

11. Which of the following is not a valid Python data type?

Mark only one oval.

a) List

b) Dictionary

c) Tuple

d) Array

12. How do you write a conditional statement in Python?

Mark only one oval.

a) if x > y then

b) if x > y:

c) if (x > y)

d) if x > y do

https://docs.google.com/forms/d/1Mu8vMR6fEs3acpTydHK8NhhYR_6HMPoJOzy5Ntd83Ts/printform 05/07/24, 9 06 AM
Page 4 of 8
:
13. How do you start a loop in Python?

Mark only one oval.

a) for x in range(5):

b) for x in 5:

c) for x to 5:

d) for x in range 5:

14. What is the correct way to import a module in Python?

Mark only one oval.

a) import module_name

b) include module_name

c) using module_name

d) require module_name

15. How do you handle exceptions in Python?

Mark only one oval.

a) using try/except blocks

b) using try/catch blocks

c) using try/error blocks

d) using try/fail blocks

https://docs.google.com/forms/d/1Mu8vMR6fEs3acpTydHK8NhhYR_6HMPoJOzy5Ntd83Ts/printform 05/07/24, 9 06 AM
Page 5 of 8
:
16. How do you create a dictionary in Python?

Mark only one oval.

a) myDict = { "key1": "value1", "key2": "value2" }

b) myDict = [ "key1": "value1", "key2": "value2" ]

c) myDict = ( "key1": "value1", "key2": "value2" )

d) myDict = < "key1": "value1", "key2": "value2" >

17. What is the output of the following code: print(len("Python"))?

Mark only one oval.

a) 5

b) 6

c) 7

d) 8

18. How do you create a set in Python?

Mark only one oval.

a) mySet = {1, 2, 3}

b) mySet = [1, 2, 3]

c) mySet = (1, 2, 3)

d) mySet = <1, 2, 3>

https://docs.google.com/forms/d/1Mu8vMR6fEs3acpTydHK8NhhYR_6HMPoJOzy5Ntd83Ts/printform 05/07/24, 9 06 AM
Page 6 of 8
:
19. How do you create a tuple in Python?

Mark only one oval.

a) myTuple = {1, 2, 3}

b) myTuple = [1, 2, 3]

c) myTuple = (1, 2, 3)

d) myTuple = <1, 2, 3>

20. How do you generate random numbers in Python?

Mark only one oval.

a) import random random.randint(1, 10)

b) include random random.randint(1, 10)

c) using random random.randint(1, 10)

d) require random random.randint(1, 10)

This content is neither created nor endorsed by Google.

Forms

https://docs.google.com/forms/d/1Mu8vMR6fEs3acpTydHK8NhhYR_6HMPoJOzy5Ntd83Ts/printform 05/07/24, 9 06 AM
Page 7 of 8
:
https://docs.google.com/forms/d/1Mu8vMR6fEs3acpTydHK8NhhYR_6HMPoJOzy5Ntd83Ts/printform 05/07/24, 9 06 AM
Page 8 of 8
:

You might also like