These questions follow Variables and Data Types and Input and Output. A variable is a name for a value; a type is what that value is allowed to do. Almost every early bug in this course is one of those two sentences being ignored.

Questions

  1. Give the type β€” int, float, str, or bool β€” for each: the number of chairs in a room; the mass of a recycling bin in kilograms; a book title; whether a permission form is in.
  2. Predict the output.
    rows = 8
    rows = rows + 4
    print(rows)
  3. Predict the output. Explain the quotation marks.
    print(type("14"))
  4. Find the fault. The club advisor types 6.5 and this crashes.
    answer = input("Kilograms collected: ")
    total = answer + 2.5
  5. Predict the output.
    minutes = 185
    print(f"{minutes / 60:.1f}")
  6. Rename these so the next reader does not have to guess: x = 12, n = "Priya", flag = True.
  7. Write a program that asks for a name and a number of days, then prints Priya, the trip is in 14 days.
  8. Challenge. A coach has total_minutes = 250. Print it as 4 h 10 min, without using a decimal point anywhere.

Answers