1 – Input and Output (Level 3)

Sample Code

Escape Characters

Escape Sequence Character
\n newline
\t tab
\b backspace
\” double quote
\’ single quote
\\ backslash
\uDDDD Unicode character
print("\u0041")

Simple Input

name = input('Enter your name: ')
print('Hello', name)

Format Output

pounds = 2
exchange = 1.38
print("{0} Pounds = {1} Euros".format(pounds, exchange))

Exercise

  1. Use the \t escape character to print out a noughts and crosses grid, as shown below in fig. 1
  2. Prompt the user to enter their (name). Print out “Hello” (name) “I hope you’re well”
  3. Prompt the user to enter their (name) and their (age). Print out (name) ” is ” (age) “years old.”
  4. Prompt the user to enter two numbers. Print out the sum of those numbers.
  5. Prompt the user to enter two numbers. Print out the average of those numbers.
  6. Prompt the user to enter their name and their age. Print out “Hello” (name) “you are” age “years old.”
  7. Get the computer to tell a Knock Knock Joke. “Knock Knock” (wait for input) “Olivia” (wait for input) “No you don’t, I live here”
  8. Print the dandelion shown in fig. 2
Table 1: fig. 1
o x
x o
o x o

fig. 2

      .--.
    .'_\/_'.
    '. /\ .'
      "||"
       || /\
    /\ ||//\)
   (/\\||/
______\||/_______

Extension

  1. Look up the current pounds to dollars exchange rate. Write a program that prompts the user to input a number of pounds and then outputs how many dollars that is.
  2. To work out your BMI, divide your weight in kilograms by your height in metres squared. In other words BMI = w / h*h. Write a program that prompts the user to input their weight and height, and then outputs their BMI.

Leave a Comment