Courseiva
Question 60 of 498
Data Types, Variables, Basic I/O and OperatorshardMultiple ChoiceObjective-mapped

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

You are maintaining a legacy Python 2.7 script that calculates shipping costs. The script reads weight from user input, then calculates cost as weight * 1.5. Recently, the company upgraded to Python 3.9, and now the script raises a TypeError: can't multiply sequence by non-int of type 'float'. The input line is: weight = input('Enter weight: '). You need to fix the script minimally. Which action should you take?

⚠ Common exam trap

Python Institute often tests the difference between Python 2 and Python 3 `input()` behavior, and the trap here is that candidates might choose `int()` (Option C) thinking weights are always whole numbers, or choose `from __future__` (Option A) without realizing it does not fix the type mismatch in Python 3.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Change the input line to weight = float(input('Enter weight: '))

In Python 3.9, `input()` returns a string, not a number. Multiplying a string by a float raises a TypeError. Option D converts the input to a float immediately, which is the minimal fix because it handles both integer and decimal weights correctly without changing the multiplication logic.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Use Python 2 style input by importing from __future__

    Why it's wrong here

    Python 2's input() evaluates expression, which is a security risk; not recommended.

  • Change the multiplication to cost = float(weight) * 1.5

    Why it's wrong here

    Although it works, it's less efficient and doesn't fix the root cause; also weight remains string for later use.

  • Change the input line to weight = int(input('Enter weight: '))

    Why it's wrong here

    int() would fail if weight contains decimal point; also loses precision.

  • Change the input line to weight = float(input('Enter weight: '))

    Why this is correct

    Converts string to float, allowing multiplication.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.