0% found this document useful (0 votes)
23 views11 pages

Python Multiple Question With Answer

Uploaded by

Sdwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views11 pages

Python Multiple Question With Answer

Uploaded by

Sdwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ADDIS ABABA UNIVERSITY [Ei-ABC]

PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

1. What is Python?
a) A high-level programming c) A hardware device
language d) A web browser
b) A database management
system
2. Which of the following is used to declare a variable in Python?
a) let c) const
b) var d) None of the above
3. What is the output of the following code?
print(2 + 3 * 4 - 6)
a) 15 c) 14
b) 17 d) 24
4. Which of the following is NOT a valid data type in Python?
a) int d) string
b) float e) char
c) boolean
5. What is the output of the following code?
print("Hello" + "World")
a) Hello c) HelloWorld
b) World d) None of the above
6. Which statement is used to exit a loop in Python?
a) break c) continue
b) exit d) return
7. What is the output of the following code?
x = [1, 2, 3, 4, 5]
print(x[2])
a) 1 c) 3
b) 2 d) 4
8. Which of the following is used to read user input in Python?
a) input() c) get()
b) read() d) scanf()

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

9. What is the correct way to write a comment in Python?


a) // This is a comment c) /* This is a comment */
b) # This is a comment d) <!-- This is a comment -->
10. What is the output of the following code?
x=5
if x > 10:
print("Greater than 10")
else:
print("Less than or equal to 10")
a) Greater than 10 c) 5
b) Less than or equal to 10 d) None of the above
11. Which of the following is used to open a file in Python?
a) open() c) file()
b) read() d) start()
12. What does the len() function do in Python?
a) Returns the length of a c) Rounds a floating-point
string or list number
b) Converts a string to d) None of the above
lowercase
13. What is the output of the following code?
x = [1, 2, 3]
y=x
[Link](4)
print(x)
a) [1, 2, 3] c) [4, 3, 2, 1]
b) [1, 2, 3, 4] d) None of the above
14. Which of the following is the correct way to define a function in
Python?
a) function my_function(): c) func my_function():
b) def my_function(): d) define my_function():

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

15. Whatis the output of the following code?


x = 10
y=3
print(x / y)
a) 3.33 c) 3
b) 3.0 d) 3.3333333333333335

////////////////////////////////////////////////////////////////////////////
Multiple questions with answer
////////////////////////////////////////////////////////////////////////////

Python Basics:

1. Which of the following is a correct way to assign a value to a


variable in Python?
a) x = 5
b) 5 = x
c) x == 5
d) x := 5

Answer: a) x = 5

2. What is the output of the following code?


print("Hello, World!")
a) Hello, World!
b) Hello World!
c) HelloWorld
d) None of the above

Answer: a) Hello, World!

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

3. How do you add comments in Python?


a) // This is a comment
b) /* This is a comment */
c) # This is a comment
d) <!-- This is a comment -->

Answer: c) # This is a comment

4. Which symbol is used for exponentiation in Python?


a) ^
b) **
c) *
d) //

Answer: b) **

5. What is the result of the following expression?


5+2*3
a) 11
b) 21
c) 17
d) 13

Answer: d) 13

Python Variables:

6. Which of the following is a valid variable name in Python?


a) my-variable
b) 123variable

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

c) _variable
d) variable#

Answer: c) _variable

7. What is the value of x after the following code is executed?


x=5
x=x+2
a) 2
b) 5
c) 7
d) 10

Answer: c) 7

8. What is the scope of a variable defined inside a function in


Python?
a) Local to the function
b) Global to the entire program
c) Global to the file where the function is defined
d) Global to the module where the function is defined

Answer: a) Local to the function

9. What is the output of the following code?


x = 10
y=5
z=x+y
print(z)
a) 105
b) 15

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

c) x + y
d) None of the above

Answer: b) 15

10. Which of the following is not a valid data type for a variable in
Python?
a) int
b) float
c) string
d) void

Answer: d) void

Python Data Types:

11. Which data type is used to represent whole numbers in Python?


a) int
b) float
c) string
d) boolean

Answer: a) int

12. What is the value of x after the following code is executed?


x = 5.0
a) 5
b) 5.0
c) "5"
d) None of the above

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

Answer: b) 5.0

13. What is the output of the following code?


x = "Hello"
y = 'World'
print(x + y)
a) Hello
b) World
c) HelloWorld
d) None of the above

Answer: c) HelloWorld

14. Which data type is used to represent a sequence of characters in


Python?
a) int
b) float
c) string
d) boolean

Answer: c) string

15. What is the output of the following code?


x = True
y = False
print(x and y)
a) True
b) False
c) None
d) Error

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

Answer: b) False

Python Conditional Statements and Loops:

16. Which keyword is used to start an "else if" block in Python?


a) elseif
b) elif
c) else if
d) elseif

Answer: b) elif

17. What is the output of the following code?


x = 10
if x > 5:
print("x is greater than 5")
elif x > 2:
print("x is greater than 2")
else:
print("x is less than or equal to 2")
a) x is greater than 5
b) x is greater than 2
c) x is less than or equal to 2
d) Multiple lines will be printed

Answer: a) x is greater than 5

18. Which of the following logical operators checks iftwo conditions


are both true in Python?
a) ||
b) &&

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

c) !
d) and

Answer: d) and

19. What is the output of the following code?


numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num)
a) 1 2 3 4 5
b) [1, 2, 3, 4, 5]
c) 5 4 3 2 1
d) None of the above

Answer: a) 1 2 3 4 5

20. What is the output of the following code?


x=0
while x < 5:
print(x)
x += 1
a) 1 2 3 4 5
b) 0 1 2 3 4
c) 0 1 2 3 4 5
d) None of the above

Answer: b) 0 1 2 3 4

Python Functions:

21. What is the keyword used to define a function in Python?

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

a) def
b) function
c) define
d) func

Answer: a) def

22. What is the output of the following code?


def greet(name):
print("Hello, " + name + "!")

greet("Alice")
a) Hello, Alice!
b) Hello, name!
c) Alice
d) None of the above

Answer: a) Hello, Alice!

23. Which of the following is not a valid way to call a function in


Python?
a) greet()
b) greet("Bob")
c) call greet()
d) greet(name="Alice")

Answer: c) call greet()

24. What is the purpose of a return statement in a function?


a) To terminate the execution of the function
b) To print a value to the console

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.


ADDIS ABABA UNIVERSITY [Ei-ABC]
PRE-EGINEERING
INTRODUCTION TO PROGRAMMING WITH PYTHON
HOME MADE MULTIPLE QUESTION EXERCISES

c) To retrieve user input


d) To send a value back to the caller

Answer: d) To send a value back to the caller

25. What is the output of the following code?


def add_numbers(x, y):
return x + y

result = add_numbers(3, 4)
print(result)
a) 3
b) 4
c) 7
d) None of the above

Answer: c) 7

Prepared by: Kibrom G., Bekuretsion B. and Kassahun T.

You might also like