Outputting Data
If you want to display something on screen you can use the print()
function. An example of code that prints to screen in IDLE is shown below:
This is what it would look like when run in IDLE:
Inputting Data
If you want the user to enter data into the program, you can use the input()
function. An example of code that will ask the user to enter their name and display it on screen using print()
is shown below:
This is what it would look like when run in IDLE:
Example program 1 - Enter a Word
The code for the program below will allow the user to enter a word and store it in a variable called word. It will then use the print()
function to output the word that they entered.
When run in IDLE:
Example program 2 - Address Program
The code for the program below will allow the user to enter various pieces of information and store them in different variables. The print()
function is then used to output all of the information.
When run in IDLE:
You can concatenate (join together) variables with strings in a print()
function. In the address example print("Street: " + number + " " + street + "\n
Town/City: " + town)
will combine the strings “Street” and “Town/City” with the variables number, street and town.
\n is used to start a new line when it is displayed on screen.