0% found this document useful (0 votes)
7 views12 pages

Python Core Concepts Lab Assignment

This document outlines the instructions for a practical assignment focused on Python core concepts, requiring students to complete guided exercises in a Google Colab notebook. The assignment includes tasks on statements, expressions, data structures, decisions, and loops, with specific deliverables due by the end of the lab session. Students must submit both a completed notebook and a summary report, with additional bonus exercises available for further practice.

Uploaded by

trangntt2410961
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views12 pages

Python Core Concepts Lab Assignment

This document outlines the instructions for a practical assignment focused on Python core concepts, requiring students to complete guided exercises in a Google Colab notebook. The assignment includes tasks on statements, expressions, data structures, decisions, and loops, with specific deliverables due by the end of the lab session. Students must submit both a completed notebook and a summary report, with additional bonus exercises available for further practice.

Uploaded by

trangntt2410961
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical Assignment 6: Python Core Concepts

Instructions for Students

Objective: Your mandatory, graded task for this lab is to complete a series of guided
exercises in a Google Colab notebook. For each topic, you will first review a complete
example and then write your own code to solve a new problem. This lab covers
Python's core concepts: statements, expressions, data structures, decisions, and loops.

Final Deliverables:

1.​ Your complete Google Colab Notebook: PA6_[YourStudentID].ipynb


2.​ Your summary text report: PA6_[YourStudentID].txt

Total Points: 20​


Deadline: Both files must be submitted by the end of this 2-hour lab session.

Part 1: Initial Setup (10 mins)..................................................................................... 3


1. Prepare Your Files................................................................................................. 3
2. Structure Your Notebook.......................................................................................3
Part 2: Guided Exercises (95 mins)............................................................................. 3
Topic 1: Statements - Input, Output, Variables (20 mins)......................................... 3
Exercise 1 (Show): Welcome Message................................................................3
Exercise 2 (Solve): Email Generator................................................................... 4
Topic 2: Expressions - Numbers & Math (20 mins)................................................. 4
Exercise 3 (Show): Area of a Circle.................................................................... 4
Exercise 4 (Solve): Time Converter.................................................................... 5
Topic 3: Objects - Lists and Tuples (15 mins).......................................................... 5
Exercise 5 (Show): Working with a Mutable List............................................... 5
Exercise 6 (Solve): Working with an Immutable Tuple...................................... 5
Topic 4: Decisions (15 mins).................................................................................... 5
Exercise 7 (Show): Simple if/else Decision........................................................ 5
Exercise 8 (Solve): Chained Decision................................................................. 6
Topic 5: Loops (15 mins).......................................................................................... 6
Exercise 9 (Show): The for loop..........................................................................6
Exercise 10 (Solve): The while loop................................................................... 6
Topic 6: Using AI Studio to Learn (10 mins)............................................................7
Exercise 11 (Task):.............................................................................................. 7
Part 3: Finalize and Submit (15 mins)........................................................................ 7
Submission Template for PA6_[YourStudentID].txt:................................................ 7

1
Part 1: Initial Setup (10 mins)

1. Prepare Your Files

●​ Open Google Colab ([Link]) and create a New Notebook.


Immediately rename it to PA6_[YourStudentID].ipynb.
●​ Open the Notepad application. Copy the entire template from the end of this
document, enter your Student ID, and save the file to your Desktop as
PA6_[YourStudentID].txt.

2. Structure Your Notebook

●​ Use Text Cells (+ Text) to create headers for each topic as you go (e.g., # Topic
1: Statements).

Part 2: Guided Exercises (95 mins)

Follow the "Show and Solve" method for each topic. First, add the "Show" example to
your notebook to understand the concept. Then, write the code for the "Solve" exercise
yourself.

1.​ Insert a new Text block, write the Title of the assignment and format it as
Heading 1 (by include 1 character ‘#’ before the title), write your Student name
and ID.

Topic 1: Statements - Input, Output, Variables (20 mins)


2.​ Insert a new Text block, write the Title of the topic and format it as Heading 1
(by include 1 character ‘#’ before the title), write your Student name and ID.

Exercise 1 (Show): Welcome Message

3.​ Insert another Text block right below the one you’ve created, write the name of
this exercise and format it as Heading 2 (by include 2 character ‘#’ before the
text). Write a short description of the exercise.
4.​ In a new code cell, type and run this example to see how input() and print()
work with strings.

2
# Exercise 1: Welcome Message
user_name = input("Enter your name: ")
welcome_message = "Hello, " + user_name
print(welcome_message)

5.​ After successfully running the code above, take a look at the algorithm below
and compare it with the code.

Exercise 2 (Solve): Email Generator

6.​ Your Task: Implement the following algorithm in a new code cell.

7.​ Record Your Work: Copy your final, working code for this exercise and paste
it into Part A, step 1 of your .txt report file.

3
Topic 2: Expressions - Numbers & Math (20 mins)
8.​ Insert a new Text block, write the Title of the topic and format it as Heading 1
(by include 1 character ‘#’ before the title), write your Student name and ID.

Exercise 3 (Show): Area of a Circle

9.​ Insert another Text block right below the one you’ve created, write the name of
this exercise and format it as Heading 2 (by include 2 character ‘#’ before the
text). Write a short description of the exercise.
10.​In a new code cell, type and run this example to see how to use the math library
and operators like **.

# Exercise 3: Area of a Circle


import math
radius = 5.0
area = [Link] * (radius ** 2)
print("The area is:", area)

Exercise 4 (Solve): Time Converter

11.​Your Task: Implement the following algorithm in a new code cell. It requires
floor division (//) and the modulo operator (%).

4
12.​Record Your Work: Copy your final code and paste it into Part A, step 2 of
your .txt file.

Topic 3: Objects - Lists and Tuples (15 mins)


13.​Insert a new Text block, write the Title of the topic and format it as Heading 1
(by include 1 character ‘#’ before the title), write your Student name and ID.

Exercise 5 (Show): Working with a Mutable List

14.​Insert another Text block right below the one you’ve created, write the name of
this exercise and format it as Heading 2 (by include 2 character ‘#’ before the
text). Write a short description of the exercise.
15.​In a new code cell, type and run this example to understand how lists can be
changed.

5
# Exercise 5: Working with a List
courses = ["Physics", "Math", "Chemistry"]
print("First course:", courses[0])
courses[1] = "Informatics" # Change an item
print("Modified courses:", courses)

Exercise 6 (Solve): Working with an Immutable Tuple

16.​Your Task: Implement the following algorithm in a new code cell.

6
Topic 4: Decisions (15 mins)
17.​Insert a new Text block, write the Title of the topic and format it as Heading 1
(by include 1 character ‘#’ before the title), write your Student name and ID.

Exercise 7 (Show): Simple if/else Decision

18.​Insert another Text block right below the one you’ve created, write the name of
this exercise and format it as Heading 2 (by include 2 character ‘#’ before the
text). Write a short description of the exercise.

# Exercise 7: Simple Decision


score = int(input("Enter your score: "))
if score >= 10:
print("Status: Pass")
else:
print("Status: Fail")


Exercise 8 (Solve): Chained Decision

19.​Your Task: Implement the following if/elif/else algorithm in a new code cell.

7
20.​Record Your Work: Copy your final code and paste it into Part A, step 3 of
your .txt file.

Topic 5: Loops (15 mins)


21.​Insert a new Text block, write the Title of the topic and format it as Heading 1
(by include 1 character ‘#’ before the title), write your Student name and ID.

Exercise 9 (Show): The for loop

22.​Insert another Text block right below the one you’ve created, write the name of
this exercise and format it as Heading 2 (by include 2 character ‘#’ before the
text). Write a short description of the exercise.
23.​In a new code cell, type and run this example to see how to iterate through a
list.

# Exercise 9: The 'for' loop


majors = ["CS", "BIT", "ICT"]
for major in majors:
print("Major:", major)

Exercise 10 (Solve): The while loop

24.​Your Task: Implement the following countdown algorithm in a new code cell.

8
25.​Record Your Work: Copy your final code and paste it into Part A, step 4 of
your .txt file.

Topic 6: Using AI Studio to Learn (10 mins)


Exercise 11 (Task):

26.​Open Google AI Studio.


27.​Write a Prompt: You need to understand how the range() function works. Ask
the AI a clear question. Prompt: "In Python, explain what range(1, 11) does
and why it doesn't include the number 11."
28.​Record Your Work:
a.​ Copy the prompt and paste it into Part B, step 5 of your .txt file.
b.​ Copy the AI's full explanation and paste it into Part B, step 6 of your
.txt file.

Part 3: Finalize and Submit (15 mins)

29.​Run All Cells: In your Colab notebook, go to Runtime > Run all. Make sure
all your code cells run without errors and that their outputs are visible.

9
30.​Download Your Notebook (.ipynb): Go to File > Download > Download
.ipynb. Save this file.
31.​Complete Your Report File (.txt): Double-check your
PA6_[YourStudentID].txt file to ensure all 6 required parts are filled in. Save it
one last time.
32.​Submit Your Assignment (Two-Part Process):
a.​ Step A (Moodle): Upload your downloaded .ipynb notebook file to the
"Practical Assignment 6 Submission" link on Moodle.
b.​ Step B (Google Form): Open the Google Form link, enter your Student
ID, and paste the entire content of your .txt report file into the form.
Click Submit.

You have now completed the assignment for Practical Class 6.

Submission Template for PA6_[YourStudentID].txt:


[STUDENT INFORMATION]
Student ID: [Your Student ID]

[PYTHON CORE CONCEPTS ASSIGNMENT]

--- Part A: Code for "Solve" Exercises ---


(Copy and paste your complete code for the 4 "Solve" exercises you
completed.)

1. Code for Exercise 2 (Email Generator):


[Paste your code for Exercise 2 here]

2. Code for Exercise 4 (Time Converter):


[Paste your code for Exercise 4 here]

3. Code for Exercise 8 (Temperature Checker):


[Paste your code for Exercise 8 here]

4. Code for Exercise 10 (Countdown):


[Paste your code for Exercise 10 here]

--- Part B: AI Studio Learning Log ---


(Describe how you used AI Studio to learn about the range() function.)

5. My Prompt to AI Studio:
[Copy the exact prompt you used to ask for an explanation]

6. The AI's Explanation:


[Copy the full explanation that the AI provided]

10
Bonus Exercises

Congratulations on finishing the main assignment! To challenge yourself further,


please choose one or more of the following bonus exercises to complete. Add your
solutions to a new section in your Google Colab notebook titled # Bonus Exercises.
There is no need to add these to your .txt report, but completing them is a great way to
deepen your understanding.

Bonus Exercise 1: The FizzBuzz Challenge (A Classic Interview Question)

Concepts Tested: Loops, Decisions, Modulo Operator (%).

Problem Statement: Write a Python program that uses a for loop to iterate through
the numbers from 1 to 30 (inclusive). For each number, it should print one of the
following:

●​ If the number is divisible by both 3 and 5, print "FizzBuzz".


●​ If the number is divisible by 3 (but not 5), print "Fizz".
●​ If the number is divisible by 5 (but not 3), print "Buzz".
●​ Otherwise, print the number itself.

Algorithm (Flowchart):

Hint: The order of your if/elif/else statements is critical. You must check for the
"FizzBuzz" condition (divisible by both) first!

11
Bonus Exercise 2: Simple List Statistics

Concepts Tested: Loops, Decisions, List Manipulation.

Problem Statement: You are given a list of student scores. Write a Python program
that iterates through the list only once to calculate the maximum score, the minimum
score, and the average score. Do not use the built-in max(), min(), sum(), or
average() functions (except to check your answer at the end).

Algorithm (Pseudocode):

1.​ START
2.​ Create a list scores = [15, 8, 20, 11, 18, 5, 13].
3.​ Initialize max_score = scores[0] (assume the first score is the highest).
4.​ Initialize min_score = scores[0] (assume the first score is the lowest).
5.​ Initialize total_score = 0.
6.​ For each score in the scores list:

Prepare yourself an algorithm and program it.

Hint: You can find the number of items in a list using the len() function (e.g.,
len(scores)).

Bonus Exercise 3: The Factorial Calculator

Concepts Tested: Loops, User Input, Variables.

Problem Statement: The factorial of a number n (written as n!) is the product of all
positive integers up to n. For example, 5! = 5 * 4 * 3 * 2 * 1 = 120. Write a Python
program that asks the user for a positive integer and then uses a loop to calculate and
display its factorial.

Prepare yourself an algorithm and program it.

Hint: You will need to initialize a variable to hold your result before the loop starts
(e.g., factorial_result = 1). Inside the loop, you will repeatedly update this variable.
You can use either a for loop with range() or a while loop for this task.

12

You might also like