02: Python: Input

Try it:

Write a program that asks for input
Input: Write a program that asks for input

Below you’ll see some example python code that will output three things to the screen.

Press Ctrl + Enter  to run the code.

Click on your score in the top right corner of the code editor to see what your code needs to do.

Any line of code that starts with a #  is a comment: it doesn’t affect how the program runs, it’s just there to help explain what the code does.

Challenges:

  1. Change Line 3 to add a question mark at the end of the question

    Notice that to display the question text in python you need to surround your question in quotation marks. The input function also needs your output to be surrounded with brackets

  2. Change line 5 to ask where you live instead

    Click on the tests button that shows your code to see exactly what question python expects you to ask. Look at test 2 and be careful with capital letters.

  3. Combine lines 7 and 8 into one line

    Notice that you can leave the brackets empty when you use input  and use print  to display the question instead. This seems inefficient (a waste of code) to me so put the question inside the brackets of input  instead.

On the next page you’ll get some code examples that have been deliberately broken for you to try to fix.

One thought on “02: Python: Input

Leave a Reply

Your email address will not be published. Required fields are marked *