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:

print("Hello World")

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:

# displays the message on screen and stores the input from the user in a variable called name
name = input("What is your name? ") 
print("Hi " + name)

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.

word = input("Please enter a word ")
print("You entered the word " + word)

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.

number = input("Enter your house number: ")
street = input("Enter your street name: ")
town = input("Enter your town/city: ")
county = input("Enter your county: ")
postcode = input("Enter your postcode: ")
print("\nAddress Details:\n" + "Street: " + number + " " + street + "\nTown/City: " + town + "\nCounty: " + county + "\nPostcode: " + postcode)

When run in IDLE:

You can concatenate (join together) variables with strings in a print() function. In the address example print("Street: " + number + " " + street + "\nTown/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.