These questions follow Data in Programs. Every program here talks to a person — which means a person can always type the unexpected.

Questions

  1. Predict the output of each line — they are not the same.
    print("Age:", 15)
    print("Age:" + "15")
  2. Predict the output when the user types Sam at the prompt.
    name = input("Who is this? ")
    print("Hi, " + name + "!")
    print("Bye, " + name + ".")
  3. Find the bug. Why does this crash, and what one change fixes it?
    age = input("How old are you? ")
    print("Next year you will be", age + 1)
  4. In n = int(input("Number: ")), describe what happens when the user types 7 — and then what happens when they type seven.
  5. Write a short program: ask for two numbers, print their sum. Test it with 3 and 4 — if it prints 34, you have found question 3.
  6. Challenge. Ask for a word and a number, then print the word that many times on one line. cat and 3 should give catcatcat.

Answers

Curriculum connection

C1.3

identify various types of data and explain how they are used within programs

Link to original

C2.1

use variables, constants, expressions, and assignment statements to store and manipulate numbers and text in a program

Link to original

C2.2

write programs that use and generate data involving various sources and formats

Link to original