15. Data Input

15.1. Data Input Conversion

  • The input function only returns strings.

  • We use the int() and float() functions to convert a value to an integer or a floating-point value respectively.

15.2. Common Error

  • Opening two parentheses and closing only one.

  • The same can happen to us with braces, brackets, quotes, among other characters. {}, [], " " whenever we open one we must remember to close it.

  • The error will end with the following:

>>> unit_value = float(input("Value of a donut: ")
File <string>, line 1
unit_value = float(input("Value of a donut: ")
                         ^
SyntaxError: '( was never closed
  • Whenever the line seems correct, check the immediately previous line.

You have attempted of activities on this page