PCAP 31 03 PCAP Certified Associate Python Programmer · Free Practice Question Easy

Question 1

Q349 - Data Types


You are an intern for ABC electric cars company.

You must create a function that calculates the average velocity

of their vehicles on a 1320 foot (1/4 mile) track.

The user needs to be able to insert floats.

Consider the following code.



The output must be as precise as possible.

What would you insert instead of ??? and ???


  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: D

Explanation

Topics: input() float() int() division operator

Try it yourself:

Explanation:

To be as precise as possible means,

that you do not want to loose the numbers after the decimal point,

if they are given by the user.

Therefore you need float() for both inputs.

Assuming the user enters a float

the function int() would raise a ValueError anyway.


Q349 (Please refer to this number, if you want to write me about this question.)

A. Using 'int' for both distance and time inputs would truncate the decimal parts, leading to inaccurate calculations for both distance travelled and time elapsed. This would result in an incorrect average velocity calculation.

B. Using 'int' for the distance input would truncate the decimal part, leading to inaccurate calculations of distance travelled. Using 'float' for the time input is correct because time can be represented as decimal values.

C. Using 'float' for the distance input is correct because distances can be represented as decimal values. However, using 'int' for the time input would truncate the decimal part, leading to inaccurate calculations of time elapsed.

D. The 'float' function is used to convert the input value to a floating-point number, which is necessary for accurate calculations involving decimal values like distance and time in this context.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need