Practice Problems

Lecture 2

Answer each number in a separate cell, either markdown or code as appropriate

Rename this notebook with your lastName and the lecture ex. Cych_02

Turn this notebook into TritonEd by the end of the second lecture.

  1. Conceptual

    • Insert a markdown cell into your practice notebook and answer the questions:
      • Why are descriptive variable names useful?
      • What are reserved words and why can't you use them as variable names?
  2. Variables

    • Insert a code cell at the bottom
    • In it, define a variable that stores the value of pi (3.1415)
    • Define a variable, radius, that stores any floating point number (radius)
    • Define a string that stores "is the circumference of a circle with radius"
  3. Operations

    • Insert another code cell into your practice notebook.
    • Calculate the circumference of a circle using the variables you defined earlier and store the answer in a separate variable.
    • print your new variable.
  4. Changing variable types

    • Convert all your variables (circumference and radius) into strings
    • Use the + operator to add them together to make this string: circumference is the circumference of a circle with radius of radius
    • boldface words are your new strings].
  5. Strings and string operation

    • Define a variable with the value:
        "Scripps Institution of Oceanography"
    • Print out the first 7 characters
    • print indices 8 to 19
    • Print index 23 to the end
  6. Putting it all together

    • Create an integer variable depth and set it to 6
    • Create a string variable planet and set it to “Earth”
    • convert the variable depth into a string
    • Create a variable ocean_depth and set it to the string: “The average ocean depth on Earth is 6 km” by using the variables depth and planet instead of Earth and 6
    • print out the variable ocean_depth
In [6]:
circumference=34
string='The circumference of the circle is'
print(string,str(circumference))
The circumference of the circle is 34
In [ ]: