"Simple Errors" raw_input() bug workaround


TL;DR you can use input() in place of raw_input by importing it from builtins

A number of folks have run into a bug w/r/t raw_input(), but fortunately there’s a workaround. Since raw_input() is Python 2 I was able to import it’s Python 3 equivalent and the bug doesn’t seem to affect it at all.


previously noted, but unresolved here:

Using raw_input() results in "Sorry, I didn’t catch that. Enter again: " being printed multiple times without any user input.

This should happen “…after I hit Run, the “Enjoying the course? (y/)” question is displayed. After I provide an aswer, the code should be validated and should get to the next step.”

You can import input() from Python 3 to get around this bug

from builtins import input

choice = input('Enjoying the course? (y/n)')

while choice != 'y' and choice != 'n':  # Fill in the condition (before the colon)
  choice = input("Sorry, I didn't catch that. Enter again: ")

:+1: yall


Thanks for the fix…

Input is now the preferred method in Python 3.

number = int(input("Enter a number: "))
string = str(input("Enter a string: "))
code = eval(input("Enter some code: "))


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.