An Introduction to Interactive Programming in Python (Part 1) - Week 0
An Introduction to Interactive Programming in Python (Part 1) - Week 0 - Statements, expressions, variables
Quiz 0
1.
Which of the following are syntactically correct strings? Try each of them in CodeSkulptor. “Hello (CHECKED) “Hello” (CHECKED) “It’s a beautiful day.” (CHECKED) ‘Hello’ Hello
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? (CHECKED) This is a comment aimed at the human reader. Python ignores such comments. This is a syntax error. This text is used as a file name for the code. This text is printed on the console.
4.
Which of the following arithmetic expressions are syntactically correct? Try each of them in CodeSkulptor. (CHECKED) (8 + (1 + (2 * 4) - 3)) 5 * 3 (7 - 2) 9 + * 4 (CHECKED) 8/-2 (CHECKED) 5 - 1 - 3 - 7 - 0
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 ounces == 16 (CHECKED) 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 CodeSkulptor. If you are still confused, you might check out the student tutorial video by Kelly on unit conversions in the “Concepts and Examples” page. mass_in_grams = 0.035274/mass_in_ounces mass_in_grams = mass_in_ounces * 0.035274 mass_in_ounces = 0.035274 * mass_in_grams (CHECKED) mass_in_grams = mass_in_ounces/0.035274
7.
Which of the following can be used as a variable name? Try using each in CodeSkulptor. 16ounces my-number (CHECKED) MYnumber (CHECKED) number123
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 CodeSkulptor. (CHECKED) x = x +y (CHECKED) x = y + x y += x+y y += x
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? On your computer only Nowhere — CodeSkulptor automatically saves your files for you (CHECKED) In “the cloud” and on your computer In “the cloud” only
Mini-project #0 - “We want… a shrubbery!” (optional)
-eof-
Quiz 0
1.
Which of the following are syntactically correct strings? Try each of them in CodeSkulptor.
2.
To display a value in the console, what Python keyword do you use?
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
4.
Which of the following arithmetic expressions are syntactically correct? Try each of them in CodeSkulptor.
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?
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 CodeSkulptor. If you are still confused, you might check out the student tutorial video by Kelly on unit conversions in the “Concepts and Examples” page.
7.
Which of the following can be used as a variable name? Try using each in CodeSkulptor.
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 CodeSkulptor.
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?
Mini-project #0 - “We want… a shrubbery!” (optional)
# program template for mini-project 0
# Modify the print statement according to
# the mini-project instructions
print "We want... a shrubbery!"
-eof-