input

Input allows you to ask the user to do something.

In Portable Python it pops up as a great user input box.
In other Python versions it asks you in the interpreter.

It can be as simple as pausing the program
input("Press the enter key to continue")

You can ask the user to make a decision
event = input("Press s to try to sneak by. Press a to attack")
This input puts the user answer into the variable event
Note that there is no guarantee that your user will type s or t.

If you want your user to input a whole number (not a negative number or a decimal fraction) you have to add int)
answer = int(input("What is 34 x 3?"))
This input puts the users answer into the variable answer.
This could then be printed, checked to see if it is correct or used in another way.
Note the extra set of parenthesis (brackets) have to be closed


If you want your user to input a decimal fraction or negative number you need to add float
answer = float(input("What is 1.2 x 3?"))
Note if the user add nothing you will get program errors

Comments