Basic Python Syntax Week1

docx

School

Grand Rapids Community College *

*We aren’t endorsed by this school

Course

266

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

3

Uploaded by ConstableWildcatMaster401

Report
Congratulations! You passed! Grade received 85.71% Latest Submission Grade 85.71% To pass 70% or higher Go to next item 1. Question 1 In the following piece of code, there is one line starting with # # . What does this line mean in Python? 1 2 3 4 5 6 7 tax_rate = 0.15 income = 40000 deduction = 10000 # Calculate income taxes tax = (income - deduction) * tax_rate print (tax) 1 / 1 point This is a comment aimed at the human reader. Python ignores such comments. This text is printed on the console. This text is used as a file name for the code. This is a syntax error. Correct 2. Question 2 Which of the following are syntactically correct strings? Try each of them in CodeSkulptor3 . 1 / 1 point "Goodbye' "Goodbye’ [Hello] [Hello] "This course is great!" "This course is great!" Correct This is a string. You can use double-quotes. "Hello, world." "Hello, world." Correct This is a string. You can use double-quotes. "'ello" "’ello" Correct This is a string. A single-quote (apostrophe) can appear inside double-quotes. 3.
Question 3 Which of the following statements uses correct Python 3 syntax to print "Hello world." "Hello world." in the console? 1 / 1 point 1 print ( "Hello world." ) 1 print Hello world. 1 print (Hello world.) 1 print "Hello world." Correct Correctly uses parentheses and quotes. 4. Question 4 Which of the following arithmetic expressions are syntactically correct? Try each of them in CodeSkulptor3 . 1 / 1 point (7 - 2) / (3 ** 2) (7 - 2) / (3 ** 2) Correct This example has correct syntax. 3 * ((2 - 9) + 4)) * (2 + (1 - 3)) 3 * ((2 - 9) + 4)) * (2 + (1 - 3)) 5 - 1 - 3 - 7 - 0 5 - 1 - 3 - 7 - 0 Correct This example has correct syntax. 5 * 3 (7 - 2) 5 * 3 (7 - 2) (8 + (1 + (2 * 4) - 3)) (8 + (1 + (2 * 4) - 3)) Correct This example has correct syntax. 5. Question 5 Which of the following can be used as a variable name? Try using each in CodeSkulptor3 . 0 / 1 point ounce(s) ounce(s) ounces ounces Correct This is a valid variable name. my-number my-number This should not be selected No, this is not a valid variable name. You cannot use a dash in a variable name. The dash is interpreted as a minus sign. MYnumber MYnumber Correct This is a valid variable name. However, convention says that Python variables shouldn't start with a capital letter.
6. Question 6 You would like to make it so that the variable ounces ounces has the value 16, thus representing one pound. What simple Python statement will accomplish this? 1 / 1 point ounces := 16 ounces := 16 ounces = 16 ounces = 16 ounces == 16 ounces == 16 16 = ounces 16 = ounces Correct Valid syntax for an assignment statement. 7. Question 7 A gram is equal to 0.035274 ounces. Assume that the variable mass_in_ounces mass_in_ounces has a value representing a given mass in ounces. Which Python statement below uses the variable mass_in_ounces mass_in_ounces to compute an equivalent mass mass_in_grams 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. 1 / 1 point 1 mass_in_grams = mass_in_ounces / 0.035274 1 mass_in_grams = mass_in_ounces * 0.035274 1 mass_in_grams = 0.035274 / mass_in_ounces 1 mass_in_ounces = 0.035274 * mass_in_grams Correct Correct.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help