15. Data Input

System Message: ERROR/3 (/home/runner/work/PyZombis/PyZombis/_sources/lectures/TWP05/TWP05_15_en.rst, line 7)

Duplicate ID – see lectures/TWP05/TWP05_15, line 11

.. activecode:: ac_l05_15a
   :nocodelens:
   :stdin:

   name = input("Write your name: ")
   print(f"Hello {name}!")

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.

System Message: ERROR/3 (/home/runner/work/PyZombis/PyZombis/_sources/lectures/TWP05/TWP05_15_en.rst, line 22)

Duplicate ID – see lectures/TWP05/TWP05_15, line 26

.. activecode:: ac_l05_15b
   :nocodelens:
   :stdin:

   unit_value = float(input("Value of a donut: "))
   n = int(input("Number of donuts: "))
   print(f"Total value: ${(n * unit_value)}")

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