CS 100

Logo

Scientific Computing

Activity 13 - What else? 🤔

The exam approaches. What else would you like to have practice with? What thing in python do you struggle with the most? Pick one or more options below. We can do any of these together in class. You can also pick ANY of the previous in-class activities.

Option A: For loops are still hard.

  1. Write a for loop to compute the sum of the first 50 numbers (1+2+3+….+49+50).
  2. Write a for loop to compute the n! ()
  3. Write a for loop that draws a square with a turtle.
  4. Write a for loop that prints out the numbers -10, -9, -8, …., 9, 10.

Option B: Turtles are still hard.

  1. Use a turtle to plot the function y = 10x + 18
  2. Use a turtle to draw a yellow triangle with a red background
  3. Use a turtle to draw a rectangle with width 300 and height 100

Option C: Functions are still hard.

  1. Write a function that uses a turtle to draw a polygon that has n sides.
  2. Write a function that takes one parameter for a person’s name and prints out “Hello” to that person.
  3. Write a function that returns the minimum of three numbers.

Option D: If statements and booleans are still hard.

  1. Write a function that returns True if x is larger than 10 and returns False otherwise.
  2. Write a function that returns True if and only if variable x is non-negative.
  3. Write a nested if statement that uses a variable snowFall and prints out:
    • “there was a hurricane today” if snowFall is over 10
    • “there was a lot of snow” if snowFall is greater than 7 but less than 10
    • “there was some snow I guess” if snowFall is greater than 3 but less than or equal to 7, and
    • “not enough snow to matter” if snowFall is less than 3

Option E: Random things are still hard.

  1. Create a function called isItRaining which returns False with 90% probability.
  2. Create a function called magicEightBallSays which randomly prints one of the following:
    • “It is certain.”
    • “Outlook good.”
    • “Ask again later.”
    • “Better not tell you now.”
    • “Very doubtful.”
  3. Create a variable called grade which randomly has the value A,B,C,D, or F.
  4. Create a variable called coinSide which randomly has the value 0 or 1.

Option F: Approximating Pi is still hard.

  1. Revisit Archimedes approximation (Activity 7)
  2. Revisit Leibniz approximation (Activity 8)
  3. Revisit Wallis approximation (Activity 8)
  4. Revisit Monte Carlo approximation (Activity 10)

Option Z: Nothing is hard.

Cool beans. Pick one question from each section (one from A, one from B, from C, from D, and from E) and complete it independently.

How to submit

Save your work in a file called activity13.py and submit to Moodle.