Quiz 0

Contents

Quiz 0#

1#

Which of the following are syntactically correct strings?

  • [ ] "Goodbye'

  • [ ] [Hello]

  • [x] "Hello, world."

  • [x] "This course is great!"

  • [x] "’ello"

2#

To display a value in the console, what Python keyword do you use?

print

3#

In the following code, there is one line starting with #. What does this line mean to Python?

tax_rate = 0.15
income = 40000
deduction = 10000

# Calculate income taxes
tax = (income - deduction) * tax_rate
print(tax)
  • [ ] This text is used as a file name for the code.

  • [ ] This text is printed on the console.

  • [ ] This is a syntax error.

  • [x] This is a comment aimed at the human reader. Python ignores such comments.

4#

Which of the following arithmetic expressions are syntactically correct?

  • [x] (7 - 2) / (3 ** 2)

  • [ ] 5 * 3 (7 - 2)

  • [x] (8 + (1 + (2 * 4) - 3))

  • [x] 5 - 1 - 3 - 7 - 0

  • [ ] 3 * ((2 - 9) + 4)) * (2 + (1 - 3))

5#

You would like to make it so that the variable ounces has the value 16, thus representing one pound. What simple Python statement will accomplish this?

  • [ ] 16 = ounces

  • [ ] ounces == 16

  • [x] ounces = 16

  • [ ] ounces := 16

6#

A gram is equal to 0.035274 ounces. Assume that the variable mass_in_ounces has a value representing a given mass in ounces. Which Python statement below uses the variable mass_in_ounces to compute an equivalent mass mass_in_grams expressed in grams?

Think about it mathematically, but also test these expressions in CodeSkulptor3. If you are still confused, you might check out this student tutorial video by Kelly on unit conversions.

  • [ ] mass_in_grams = mass_in_ounces * 0.035274

  • [ ] mass_in_grams = 0.035274 / mass_in_ounces

  • [x] mass_in_grams = mass_in_ounces / 0.035274

  • [ ] mass_in_ounces = 0.035274 * mass_in_grams

7#

Which of the following can be used as a variable name?

Try using each in Python.

  • [x] MYnumber

  • [x] number123

  • [ ] 16ounces

  • [ ] my-number

8#

Assume you have values in the variables x and y. Which statement(s) would result in x having the sum of the current values of x and y?

Test your answer in Python.

  • [ ] y += x

  • [ ] y += x+y

  • [x] x = y + x

  • [ ] x = x + y

9#

Python file names traditionally end in what characters after a period? Don’t include the period.

py

10#

We encourage you to save your CodeSkulptor Python files where?

  • [x] In “the cloud” and on your computer

  • [ ] In “the cloud” only

  • [ ] Nowhere — CodeSkulptor automatically saves your files for you

  • [ ] On your computer only

It is a good practice to save your files locally, as Codeskulptor may delete your files after some time.