ML 131: Generating Python Code with Bard (40 pts extra)

What You Need

Purpose

To practice generating Python code with Bard.

Using Google Bard

In a browser, go to
https://bard.google.com/
Agree to any conditions that pop up.

At the bottom, in the "Enter a prompt here" field, enter this prompt:

Write Python code to count from 1 to 10 and run it.
Bard writes the code, and explains how it works, as shown below.

Exporting the Code to Colab

Scroll to the bottom of the Bard window.

Click the up-arrow icon, and click "Export to Colab", as shown below.

A box pops up, saying "New notebook saved in Drive." Click "Open Colab".

Colab opens, with both the code and the explanation, as shown below.

Modifying the Code

In the code box, in the range() command, add a third parameter of 2, outlined in white in the image below.

Click the run button on the left side of the code box, outlined in red in the image below.

ML 131.1: Product (5 pts)

Carefully modify the code to match the image below. Make sure the indentation of the lines you add is correct.

Run that code.

The flag is covered by a green rectangle in the image below.

ML 131.2: Primes (10 pts)

In Bard, on the left, click "Reset chat". Click Reset.

In Bard, enter this prompt:

Write Python code to generate the first ten prime numbers. Include only every other result. Multiply the remaining numbers together. Display the original list of primes, the list with only every other number included, and the resulting product.
Export the code to Colab and run it.

The code fails, as shown below.

Fix the code to see the flag, covered by a green rectangle in the image below.

ML 131.3: Fibonacci (10 pts)

Generate the first ten Fibonacci numbers, excluding the first one. As you did above, multiply every other one together to see the flag, covered by a green rectangle in the image below.

ML 131.4: 1000 Primes (15 pts)

Generate the first 1000 prime numbers. Add every hundredth one together. The flag is covered by a green rectangle in the image below.

Posted 7-5-23