0% found this document useful (0 votes)
13 views19 pages

Python Basics and Assignments Overview

Gh

Uploaded by

razwan shahad
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)
13 views19 pages

Python Basics and Assignments Overview

Gh

Uploaded by

razwan shahad
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

Introduction to Python Basics

Week 1:
Understanding Programming Concepts and Python Basics. Installing Python
and Setting up the Development Environment.
Please read the following article carefully and try to understand the concepts.
[Link]
?usp=sharing

Watch the following video to understand the concepts and learn how to install
the required applications.
[Link]

Assignment-1

1. Using two integers designated as vNum1 and vNum2, calculate their


sum using the + operator, and then print the resulting sum without
user input.

2. Using two integers designated as vNum1 and vNum2, calculate their


sum using the + operator, and then print the resulting sum with user
input. Users should be able to provide two numbers that they want to
add.

3. Reflection: Write a 2–3-page document reflecting on the video


tutorial, describing:

a. What were the key steps involved in creating pentagons,


triangles, and hexagons using the Turtle module?

b. Discuss the significance of using a graphics module like Turtle


in Python for educational purposes, particularly in teaching
concepts such as geometry and programming logic
simultaneously.
c. What are some of the fundamental Turtle module commands
or functions demonstrated in the video, and how did they
contribute to the creation of geometric shapes?

d. In your own words, describe the role of the Turtle module in


Python and its relevance in the context of computer graphics
and educational programming.

e. Reflect on any challenges or difficulties you encountered while


following the video tutorial and how you overcame them, if
applicable.

f. How does experimenting with parameters such as angles, side


lengths, and colours in the Turtle module enhance your
understanding of geometric concepts and programming
principles?

These questions are designed to encourage critical thinking, reinforce


understanding of programming concepts, and promote active
engagement with the Turtle module and geometric shapes in Python.

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 2:
Data Types: Strings, Integers, Floats, Lists, Sets, and Booleans

Watch the following video and make sure you understand all the concepts:
[Link]

Assignment-2

Objective: This assignment aims to familiarize students with basic Python


syntax and variables. The concept of variables will be discussed in detail in
Week 3. It is recommended that you watch the Week 3 video before
completing the following assignments.

1. Write a Python script that takes the user's name as input and prints a
personalized greeting.

2. Calculate the area of a rectangle with a user-specified length and


width. Print the result.

3. Reflection: Write a 2–3-page document reflecting on the video


tutorial. Describe different data types mentioned in the video and
provide some examples.

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 3:
Variables in Python
Watch the following video and ensure you understand all the concepts:
[Link]

Assignment-3

Objective: This assignment aims to familiarize students with basic concepts of


variables and their appropriate use.
1. Write a Python script that uses several valid variable names to store
strings, integers, floats, lists, and dictionaries. Please refer to the
video in week 2. Submit a single .py file for this assignment via
Google Classroom when instructed.

2. Create another Python program that uses the type() function to


describe the type of the variables. Please use all commonly used data
types described in the video from week 2. Print the results.

Assignment 3.2: Student Grade Calculator

1. Develop a Python program that calculates the average grade of


students based on their scores in multiple subjects.

Requirements:

a. Define variables for the number of subjects and the total scores.
b. Ask the user to input the number of subjects.
c. Use a loop to input scores for each subject and calculate the total
score.
d. Calculate the average grade (total score divided by the number of
subjects).
e. Display the average grade along with a grading scale (e.g., A for
90-100, B for 80-89, etc.).
Example Output:

Challenge: Implement validation to ensure that the input scores are within a
valid range (e.g., 0-100 for grades).

These assignments will require students to utilize variables effectively, handle user
input, perform calculations, and apply conditional logic as needed. They provide
practical exercises that can enhance students' understanding of variables and
programming concepts in Python.

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 4:
Arithmetic Operators in Python: Basic Operators and Expressions
Watch the following video and ensure you understand all the concepts:
[Link]

Assignment-4
1. Write a Python script that takes input from users and prints a times
table. Please refer to the video above if you need help. Submit a
single .py file for this assignment via Google Classroom when
instructed.

2. Reflection: Write a 2-page document reflecting on the video tutorial,


describing what arithmetic operators are in Python. Why did we use
the int() function in the video? How many different arithmetic
operators were used in the video?

3. An Alt code was used in the video. What is the code, and what does it
do? Provide some other examples of Alt codes of your choice that
can be used for mathematical operations.

1. Type the following in you IDE:

Check to see what you get as a result and explain your findings in a single-page
document. Please submit the document to Google Classroom when requested.
Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 5:
String Formatting
Read the following article to understand what string formatting is. Questions
will be asked from this document during the final exam.
[Link]
87265402&rtpof=true&sd=true

Watch the following video to answer the questions that follow:


[Link]

Assignment-5
1. Reflection: Write a single-page document describing which string
formatting method has been used in the video.

2. Describe the purpose of `{vnum:.5f}` and what it does. Explain your


answer in a single-page document. Please submit the document to
Google Classroom when requested.

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 6:
Inplace Arithmetic Operators
Read the document below and make sure you understand it thoroughly.
[Link]

Watch the following video to answer the questions that follow:


[Link]

Assignment 6:
1. Reflection: Write a single-page document describing inplace arithmetic
operators and their purpose.

2. Identify another important concept used in the video.

3. Write a Python script to create a times table as shown in the video using
a while loop. Submit a single .py file to Google Classroom when
requested.

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 7:
List Comprehension
Read the following article to understand what a list comprehension is.
Questions will be asked from this document during the final exam.
[Link]
87265402&rtpof=true&sd=true

Watch the following video to answer the questions that follow:


[Link]

Assignment 7:
1. Reflection: Write a single-page document defining and describing list
comprehension and discussing the benefits of using list comprehension.
2. Create a simple program that uses list comprehension. You can use
examples from the video or come up with your own program.

Week 8:
Loops - for and while loops
Read the following document to understand loops in Python, including for and
while loops. Questions will be asked from this document during the final exam.
[Link]
ing&ouid=109682884996587265402&rtpof=true&sd=true

Assignment 8:
1. Reflection: Write a single-page document defining and describing loops
in Python and explaining why they are super useful in programming.

2. Recreate the two projects described in the following video:


[Link]

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 9:
Control Flow: if statement and conditions

Read the following article to understand what control flow and if statements
mean. Questions will be asked from this document during the final exam. It is
important to know the definition of Control Flow in Python by heart.
[Link]
ring&ouid=109682884996587265402&rtpof=true&sd=true

Watch the following video to understand the concepts:


[Link]

Assignment-9:
1. Reflection: Write a single-page document describing your understanding
of control flow and how it is used in programming for decision-making.

2. Create two projects of your choice that use control flow by using if, elif,
and else statements.

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 10:
List and Dictionary – Data Types

Watch the following video to understand the concepts:


[Link]

Assignment-10:

1. Create a Python list that has numbers from 1 to 10 in random order. In


the program, write three print statements showing index positions of
three different numbers from the list that you created. Submit a single
.py file to Google Classroom when requested.

2. Recreate the solution to a challenge from [Link] using different


variable names. Submit the .py file to Google Classroom when requested.

3. Write a 1-2 page document discussing [Link] and how it can be


used to improve skills in Python and prepare for job opportunities in
international markets, enabling earning in foreign currencies. Submit the
document to Google Classroom when requested.

4. Create two projects of your choice from [Link] and submit the
.py files to Google Classroom when requested.

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 11:
Code Execution – Code execution in a Python project using dictionaries
Watch the following video to understand the concepts:
[Link]

Assignment-11

1. Reflection: Write a 1–2 page document describing why it is important to


understand how code executes in any program. Provide a detailed
reflection on what you learned in the following video:
Submission Guidelines: Submissions should be uploaded to the Google Classroom assignment
when requested.
Week 12:
Slice Operator
Read the following article to understand what a slice operator is. Questions will
be asked from this document during the final exam.
[Link]
aring&ouid=109682884996587265402&rtpof=true&sd=true

Watch the following video not only to understand the concepts but also see
the slice operator in action to solve a [Link] challenge.
[Link]

Project: Text Analyzer


Project Description:

The Text Analyzer project is designed to help students analyse text input
provided by the user. It involves processing the text to extract useful
information such as word count, character count, and generating word
frequency statistics using the slice operator.

Features to Include:
1. Word Count: Calculate the total number of words in the input text.
2. Character Count: Calculate the total number of characters in the
input text.
3. Word Frequency: Generate a dictionary that stores the frequency of
each word in the text.

2. Implementation Steps:

1. Input Processing:

a) Ask the user to input a piece of text (could be a paragraph


or multiple sentences).
b) Clean the input text by removing any leading or trailing
whitespace characters.
3. Word Count:
a) Split the cleaned text into words using the `split()` method.
b) Use the slice operator to get a sublist of words for
counting.

4. Character Count:

a. Use the slice operator to get a sublist of characters from the


cleaned text for counting.

5. Word Frequency:
a) Create an empty dictionary to store word frequencies
(`word_freq = {}`).
b) Iterate through the list of words obtained from the cleaned
text.
c) For each word, update its frequency in the dictionary using
the slice operator to access and modify the dictionary.

6. Display Results:
7. Print the word count and character count obtained in steps 2 and 3.
8. Display the word frequency statistics by printing the word-frequency
dictionary.

Project Extensions:
1. Implement additional features such as finding the longest word, shortest
word, or average word length in the text.
2. Allow the user to analyse text from a file rather than inputting it
manually.
3. Enhance the word frequency analysis by excluding common stop words
or implementing stemming/lemmatization for better accuracy.
4. This project provides a practical application of the slice operator while
also improving students' understanding of text processing and basic
data analysis in Python.
[Link]
VXtTA2x/edit?usp=sharing&ouid=109682884996587265402&rtpof=true&sd=true

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 13:
Functions
Watch the following video to understand functions and answer the questions
that follow:
[Link]

Task:
The video describes some built-in functions and a couple of user-defined
functions were also created in the video. Write a minimum of a 2-page article
describing some of the built-in functions used in Python. Python comes with a
substantial number of built-in functions that are readily available for
programmers to use. These functions are part of the Python standard library
and cover a wide range of tasks, from basic operations to more specialized
functionalities. The exact count can vary slightly depending on the Python
version and distribution, but typically, there are over 60 built-in functions in
Python 3. Please search online to find more built-in functions and provide a list
of at least 15 built-in functions in Python, including those mentioned in the
video.
Assignment 13:
Exploring Functions in Python
Objective:
The objective of this assignment is to deepen your understanding of functions
in Python, including function definitions, parameters, return values, and
function calls.
1. Function Basics:

Define a function named `greet_user` that takes a parameter `username` and


prints a greeting message like "Hello, [username]! Welcome to Python
Functions."

2. Function Parameters:

Define a function named `calculate_area` that takes two parameters `length`


and `width` and returns the perimeter of a rectangle (Perimeter=2×(length +
width)).
3. Default Parameters:

Define a function named `calculate_volume` that takes three parameters


`length`, `width`, and `height`, where `height` is optional with a default value of
1. This function should return the volume of a rectangular prism (volume =
length * width * height).

4. Return Values:

Define a function named `is_even` that takes a parameter `number` and returns
`True` if the number is even, otherwise `False`.

5. Function Calls:

Call each of the functions defined above with appropriate arguments and print
the results.

6. Function Composition:

Define a function named `calculate_total_cost` that takes parameters `price`


and `quantity` and calculates the total cost (total_cost = price * quantity). Then,
define another function named `apply_discount` that takes parameters
`total_cost` and `discount_rate` (default value 0.1 for 10% discount) and
returns the discounted cost. Finally, call these functions in sequence to
calculate and print the discounted cost.

7. Challenges (Optional):

Create your own custom functions with different functionalities and use them
in meaningful ways to solve problems or perform calculations.

Submission Instructions:
- Write Python code to complete the tasks outlined above.
- Organize your code neatly with appropriate comments.
- Include meaningful variable names and function names.
- Test your functions with different input values to ensure correctness.

This assignment structure covers a range of concepts related to functions in Python,


from basic function definitions to more advanced topics like default parameters and
function composition. Students will have the opportunity to practice writing functions,
working with parameters, and understanding return values, which are fundamental
skills in Python programming. Feel free to modify or expand upon these tasks based on
your students' proficiency level and learning objectives.

Submission Guidelines: Students should create a single Python script (.py file) containing the
code for all tasks. The code should be well-commented. Optionally (not mandatory), you can
follow the PEP 8 style guidelines. Submissions should be uploaded to the Google Classroom
assignment when requested. Please search online to find out what the PEP 8 style guidelines
are.
Week 14:
Following video will help you to complete this project.
[Link]

Project Title: Even Numbers Sorter


Project Description:
In this project, you will write a Python program to find all the even numbers
from a given list of integers and then sort them in descending order.

Project Tasks:
1. Create a Python script or function that takes a list of integers as input.
2. Write code to filter out only the even numbers from the input list.
3. Implement sorting functionality to arrange the even numbers in descending
order.
4. Test your program with different lists of integers to ensure it works correctly.
5. Provide a user-friendly interface or instructions for inputting lists and
displaying the sorted even numbers.

Project Requirements:
1. The program should handle both positive and negative integers in the input
list.
2. Ensure that the program properly sorts the even numbers in descending
order.
3. Include comments and clear variable names to enhance code readability.
4. Test the program with various input lists, including edge cases like an empty
list or a list with only odd numbers.
Bonus Tasks (optional):
Modify the program to accept user input for the list of integers.
Implement error handling to deal with invalid input, such as non-integer
elements in the list.
Add functionality to calculate and display the sum of the sorted even numbers.
The project "Even Numbers Sorter" is designed to help you practice filtering and sorting even numbers from a list of
integers in Python. It includes a set of tasks and requirements to ensure your program is robust and user-friendly.
Good luck with your project!
Week 15:
Task: Create a new script to achieve the same functionality as in week-14, but
this time use a function and the built-in `sorted()` function.
[Link]

Week 16:
Watch the following video to understand how to create a function that
identifies prime or composite numbers.
[Link]

There are no assignments this week, but it is likely that you may be required to
recreate this project in the final exam.

Week 17:
Watch the following video to understand how to create a function that
identifies prime or composite numbers.
[Link]

There are no assignments this week, but it is likely that you may be required to
recreate this project in the final exam.

Week 18:

Please read the following article carefully and try to understand the concepts:
[Link]
109682884996587265402&rtpof=true&sd=true

Watch the following video to understand how to create a function that


identifies prime or composite numbers.
[Link]

These tasks and resources are provided to help you deepen your understanding of Python
programming concepts. Good luck with your learning!

Common questions

Powered by AI

Building functions in Python significantly enhances modularity and reusability in software development by encapsulating specific tasks into callable units, which encourages code separation and clarity. By defining functions, developers create reusable components that can be tested and debugged independently, improving maintainability. For example, calculating the area of a rectangle can be encapsulated in a function, allowing repetitive use without rewriting logic each time. This modular approach fosters scalability, as functions can be easily modified or extended without impacting other code areas, promoting efficient and effective software development .

Combining loops and list comprehensions enhances Python code functionality and readability by compactly expressing operations that iteratively transform data collections. While loops provide the backbone for iteration, list comprehensions allow these iterations to be expressed in a single line, increasing readability and reducing boilerplate code. For example, transforming a for-loop that appends squared even numbers to a list into a comprehension like `[x**2 for x in range(10) if x%2 == 0]` consolidates the entire sequence of operations into a concise expression, simplifying comprehension and maintenance .

Understanding the PEP 8 style guide strategically enhances Python programming by promoting consistency, readability, and maintainability across codebases. It influences code quality by setting standards for code aesthetics, such as indentation, line length, and naming conventions, which reduce complexity when codebases are shared across teams. By adhering to these guidelines, developers create code that is easier to understand and navigate, minimizing errors and improving collaboration. This practice becomes essential in large-scale projects, where uniformity ensures that any developer can seamlessly read and contribute to the code .

The 'Even Numbers Sorter' project addresses challenges in filtering and sorting integer lists, requiring comprehensive handling of data type operations. It involves extracting even numbers and sorting them in descending order, demanding efficiency in both filtering logic and sorting algorithms. Handling edge cases such as empty lists or lists with no even numbers is crucial to prevent errors. These can be managed by incorporating input validation and checks before processing, ensuring stability. By covering both typical and atypical inputs, the program demonstrates robust design suitable for real-world scenarios .

Control flow using if, elif, and else statements allows for decision-making in Python programs by executing different blocks of code based on conditions. The 'if' statement checks a condition and executes its block if the condition is true. If false, the 'elif' (else if) statements can define additional conditions to test. If none of these conditions are met, the 'else' block executes. This structure is crucial for implementing logic that requires branching, enabling programs to respond dynamically to different inputs or states .

List comprehensions streamline Python code by allowing for more concise and readable expressions compared to traditional for-loops. They enable the creation of lists in a single line, integrating the creation and transformation processes. This not only simplifies the code but can also lead to performance improvements due to optimizations implemented at the interpreter level. For instance, `[x**2 for x in range(10)]` efficiently constructs a list of squares without separate loop and append statements. Such comprehensions often reduce the cognitive load and improve code maintainability .

The Turtle module in Python is beneficial for educational purposes as it provides a visual way to understand geometry and programming logic simultaneously. By using Turtle, learners can see the immediate impact of their programming on shape formation, which helps in reinforcing concepts such as angles, loops, and functions. The visual feedback makes abstract concepts more concrete, aiding in better retention and understanding. Additionally, experimenting with parameters like angles and side lengths deepens a learner's understanding of geometric transformations and programming constructs .

Inplace arithmetic operators enhance efficiency in programming by directly modifying the operands, which can lead to performance improvements, especially in large-scale operations. Instead of creating new objects for results, these operators update the existing object's value. For example, 'x += 1' updates 'x' in place rather than creating a new object for the result. Other operators like '-=', '*=' can similarly optimize performance by reducing the overhead associated with object creation .

String formatting methods in Python enhance data presentation and manipulation by allowing precise control over output formatting, which is essential for producing readable reports and logs. `{vnum:.5f}` serves a specific purpose by formatting the value of `vnum` to five decimal places, ensuring consistency and precision in numeric displays. This is particularly useful in financial applications where maintaining exact decimal points is crucial, or in scientific computations where significant figures matter. Such formatting capabilities are vital for creating user-friendly interfaces and maintaining data integrity .

Experimenting with parameters such as angles, side lengths, and colors in the Turtle module fosters a deeper understanding of both geometric shapes and programming principles. By adjusting these parameters, students can directly observe their effects on the shapes drawn, enhancing comprehension of geometry concepts like symmetry and proportion. Moreover, this interactive approach allows learners to apply logical thinking and control structures, as they tweak parameters to achieve desired outcomes, thus reinforcing fundamental programming principles including iteration and conditional logic .

You might also like