wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is the primary purpose of the decimal module in Python?

a)

To perform faster arithmetic operations than standard floats.

b)

To handle financial calculations and ensure exact decimal representations.

c)

To convert numbers between different bases (binary, octal, hexadecimal).

d)

To provide advanced mathematical functions like trigonometry and logarithms.

2.

What will be the output of the following Python code? from decimal import Decimal print(Decimal('0.3') + Decimal('0.2') == Decimal('0.6'))

a)

True

b)

False

c)

Error

d)

Machine dependent

3.

To represent the fraction 3/4 accurately in Python, which of the following is the most appropriate?

a)

0.75

b)

3 / 4

c)

fractions.Fraction(3, 4)

d)

decimal.Decimal('0.75')

4.

What is the result of fractions.Fraction(1, 3) + fractions.Fraction(1, 6)?

a)

fractions.Fraction(1, 2)

b)

fractions.Fraction(2, 9)

c)

0.5

d)

fractions.Fraction(3, 18)

5.

Which of the following is an incorrect way to create a Decimal object from a floating-point number in a way that might introduce precision issues?

a)

Decimal(0.1)

b)

Decimal('0.1')

c)

Decimal(str(0.1))

d)

None of these

6.

What is the result of Decimal('1.200').normalize()?

a)

Decimal('1.200')

b)

Decimal('1.2')

c)

Decimal('1.20')

d)

Decimal('1.2e+0')

7.

Which of the following is a valid way to create a Money object?

a)

my_money = Money(10, "USD")

b)

my_money = Money("10", "USD")

c)

my_money = Money(10 USD)

d)

my_money = Money(amount=10, currency="USD")

8.

What is the correct way to create a complex number in Python?

a)

complex(real, imaginary)

b)

real + imaginary_i

c)

real + imaginaryj

d)

complex_number(real, imaginary)

9.

Which of the following functions in the random module returns a floating-point number between 0.0 (inclusive) and 1.0 (exclusive)?

a)

randint()

b)

randrange()

c)

random()

d)

uniform()

10.

Which function is used to randomly select a single element from a non-empty sequence (like a list or tuple)?

a)

random.sample()

b)

random.shuffle()

c)

random.choice()

d)

random.choices()

11.

Which of the following functions from the math module returns the smallest integer greater than or equal to a given real number?

a)

math.floor()

b)

math.ceil()

c)

math.trunc()

d)

math.round()

12.

What is the output of print(math.fabs(-5.7))?

a)

-5.7

b)

5.7

c)

5

d)

-5

13.

What is the output of the following Python code? import math print(math.log(100, 10))

a)

1

b)

2

c)

2.0

d)

10

14.

To convert an angle from radians to degrees in Python, which function from the math module would you use?

a)

math.radians()

b)

math.degrees()

c)

math.convert_to_degrees()

d)

math.rad_to_deg()

15.

What will be the output of the following Python code? class tester: def __init__(self, id): self.id = str(id) id="224" temp = tester(12) print(temp.id)

a)

12

b)

224

c)

None

d)

Error