ExamVeda
Login
Home
21
What is the result of 5 / 2 ?
Discuss
Answer & Solution
Answer: Option A
Solution:
Division of two integers results in a floating-point number.
22
Which of the following results in a SyntaxError?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
23
What is the imaginary part of the complex number 3 + 4j ?
Discuss
Answer & Solution
Answer: Option B
Solution:
The imaginary part of a complex number is the coefficient of the imaginary unit j.
24
What is the average value of the following Python code snippet?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
25
What is the result of int(3.999) ?
Discuss
Answer & Solution
Answer: Option A
Solution:
The int() function converts a floating-point number to an integer by truncating the decimal part.
26
What does ~4 evaluate to?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
27
What is the output of print 0.1 + 0.2 == 0.3?
Discuss
Answer & Solution
Answer: Option B
Solution:
When we talk about numbers with decimal points (like 0.1, 0.2, 0.3) in computers, we call them "floating-point numbers".

Computers work with a system of 0s and 1s (called binary). It's very easy for them to represent whole numbers (like 1, 2, 10). But when it comes to decimal fractions, it can be a bit tricky.

Think of it like trying to write 1/3 as a decimal number. You get 0.33333... and it goes on forever! You can never write it *exactly* with a finite number of digits.

The same thing happens in computers with numbers like 0.1, 0.2, and 0.3 when they try to represent them in binary. They can't represent them *exactly*. Instead, they store a very, very close approximation.

So, when you do 0.1 + 0.2:
1. The computer takes its *approximation* of 0.1.
2. It takes its *approximation* of 0.2.
3. It adds these two approximations together. The result is an *approximation* of 0.3.

Now, when you compare this sum (the approximation of 0.1 + approximation of 0.2) with the computer's *approximation* of 0.3 using ==, Python checks for exact equality. Because of those tiny, tiny differences in the approximations, the sum of approximations of 0.1 and 0.2 is usually not *exactly* equal to the approximation of 0.3.

It's like saying 0.333 is exactly equal to 0.334 – they are very close, but not exactly the same.

Therefore, the expression 0.1 + 0.2 == 0.3 evaluates to False.

This is a common behavior with floating-point numbers in most programming languages, not just Python. It's important to remember this when dealing with financial calculations or anything that requires extreme precision with decimals.
28
The following is displayed by a print function call. Select all of the function calls that result in this output.
tom
dick
harry
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
29
What is the data type of the result of "True" ?
Discuss
Answer & Solution
Answer: Option B
Solution:
The result of "True" is a string, not a boolean.
30
What is the result of cmp(3, 1)?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board