basic io

Open your text editor and create a file called (“io” is short for input/output). Write some commands in it to do the following:

  1. use input to get the user’s name
  2. use print to display a friendly greeting

After you write the commands, running the file should give you output like this:

$ python
What is your name? kevin
Go away kevin

Good luck! I’ve provided a solution below, but try to write the program without looking at it first. You may need to go back to the print, variables or input pages to refresh your memory.

Show solution

name = input("What is your name? ")
print("Go away", name)


See the first line that starts with a #? That’s a “comment.” Python will ignore everything that comes after the #, so you can use them to write notes to whoever is reading the code. Here, I’ve used a comment to tell you the name of the file.

previous: batch mode next: arithmetic