Being-Creative-with-AI/C3/Using-Gemini-in-Google-Colab/English

From Script | Spoken-Tutorial
Revision as of 16:24, 15 May 2026 by Misbah (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Visual Cue Narration
Slide 1

Title Slide

Welcome to this Spoken Tutorial on Using Gemini in Google Colab.
Slide 2

Learning Objectives

In this tutorial, we will learn to:
  • Enable Gemini in Colab.
  • Generate Python code.
  • Explain code.
  • Debug errors.
Disclaimer Content Slide As AI tools constantly evolve, if you are unable to locate any icon or encounter difficulty at any step, you may use any conversational AI Chatbot for guidance.
System Requirement To record this tutorial, I am using:
  • Ubuntu 24.04 L T S.
  • Firefox version 148.0.2 and
  • A working internet connection.
Prerequisites

For the Pre-requisites of this tutorial, visit the website shown on your screen

http://EduPyramids.org

To follow this tutorial, learners should have basic knowledge of computers.

They should also be familiar with using a web browser.

For the Pre-requisites of this tutorial, visit the website shown on your screen.

Code files

The following code file is required to practice this tutorial

gc-command.txt

This file is provided in the Code Files link of this tutorial page.

Please download and extract the file.

The following code file is required to practice this tutorial.

This file is provided in the Code Files link of this tutorial page.

Please download and extract the file.

Gemini in Google Colab Gemini in Google Colab helps generate, explain, and debug code.

It does not require an A P I key.

A P I keys are used in applications.

Getting started Let us get started.
Type:

https://colab.research.google.com/

and press the Enter key.

You can use any browser.

I'm using Firefox.

Type this URL and press the Enter key.

Click on the +New notebook button. Open notebook window appears.

Let us create a new notebook.

Click the Plus New notebook button at the bottom left corner of the page.

New notebook page A New notebook page opens.
Gemini Toggle Highlight

Click on the Gemini Toggle.

Locate the Toggle Gemini icon at the bottom.

Click the toggle to enable Gemini.

Colab Privacy Notice window A Colab Privacy Notice window displays.

Click on Continue.

Cursor on Gemini Panel View The Gemini panel appears on the right side of the screen.
Type the prompt:

Write a Python program to calculate factorial.

Press Enter.

In the prompt area, type: Write a Python program to calculate factorial.

Press the Enter key.

You can also press the arrow button to run the code.

Point the cursor to the generated code. The code gets generated in the notebook.
Click the Accept & Run button. Click Accept & Run to execute the code.
Highlight the Output The code gets executed and displays the output.
At the prompt,

Type: Explain this code line by line and press Enter.

Type: Show how it computes factorial of 5 and press Enter.

Now at the prompt, type: Explain this code line by line and press Enter.

We can see each and every line of code is explained thoroughly.

Now type the prompt: Show how it computes factorial of 5 and press Enter.

Point the cursor to the explanation. Gemini displays the explanation clearly.
Introducing error Now, let us introduce an error in the code.
Select the code from the notebook and delete it. Clear the colab screen by clicking on 'Delete cell' icon.
Copy paste the code from the text editor.

def factorial(n):

   result = 1
   for i in range(1, n):
   result = result * i
   return result

print(factorial(5))

Click on the plus Code icon.

A new code cell displays.

Copy paste the code from the text editor in the code cell.

Highlight the Code. There are 2 errors in this code.

At first glance, the code looks correct, but it contains some errors.

The first error is an indentation error.

Highlight result = result * i This line is not indented inside the for loop.

In Python, indentation defines the structure of the program.

Because, Python will throw an indentation error and the code will not run.

Highlight range(1, n) The second error is a logical error in the range function.

The range function excludes the last value.

It runs from 1 to 4 instead of 1 to 5.

Click on Run cell icon Now click on Run cell icon to execute the code.

Observe the error.

Type: Why is it showing an error?

And press the Enter key.

In the Gemini panel, type: Why is it showing an error?

Press Enter.

In the Gemini panel, we can see an explanation of what the error is.

Now type: Fix the code and explain and press Enter. Now type: Fix the code and explain and press Enter.
Highlight the Gemini suggestion.

Click on the Accept & run button.

Gemini suggests using a range from 1 to n plus 1.

Click on Accept & run, to execute the code.

Highlight the output indicating the code is correct. The code gets executed and the output is shown.
Caution Slide Please note the following caution points.
  • Do not copy code blindly.
  • Always run and verify the output.
Summary With this, we come to the end of this tutorial.
Summary Let us summarize.

In this tutorial, we learnt to:

  • Enable Gemini in Colab.
  • Generate Python code.
  • Explain code.
  • Debug errors.
Assignment

As an assignment,

Generate a program with constraints, introduce an error, and fix it using Gemini.

We encourage you to do this assignment.
Acknowledgement slide Thank you for joining.
Closing slide

This Spoken Tutorial is brought to you by

EduPyramids Educational Services Private Limited, SINE, IIT Bombay.

Contributors and Content Editors

Madhulika, Misbah