The input()
function in Python allows the user to give input from the console.
When a compiler encounters the input()
function, the program pauses for the user to give input and then the remaining code executes.
Below is an example of a code where the user is asked a question and the code is executed based on the user’s response.
Click on the >_ STDIN
button and write your answer to the quest in the stdin block that pops below.
Running the code below without the input will generate an error.
print('What is 2+2 equal to?')x = input()if x==4:print(str(x) + ' is the correct answer!')else:print(str(x) +' is the wrong answer!')
Enter the input below
Free Resources