0% found this document useful (0 votes)
3 views

Homework 0 - Python Basics

This document outlines a homework assignment for a Machine Learning module at the University of Constantine 2, focusing on Python basics. It includes exercises on core syntax, data structures, function creation, and grade categorization. Students are required to work with files, loops, conditionals, and dictionaries to analyze student grades and implement various functions.

Uploaded by

zitouni2midou
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Homework 0 - Python Basics

This document outlines a homework assignment for a Machine Learning module at the University of Constantine 2, focusing on Python basics. It includes exercises on core syntax, data structures, function creation, and grade categorization. Students are required to work with files, loops, conditionals, and dictionaries to analyze student grades and implement various functions.

Uploaded by

zitouni2midou
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

UNIVERSITY OF CONSTANTINE 2 - ABDELHAMID MEHRI

FACULTY OF NTIC - DEPARTMENT OF TLSI M1 – SDSI


2024 – 2025
MODULE: MACHINE LEARNING

HOMEWORK 0: RECALL ON PYTHON BASICS


(Duration: 1 day)

Learning Objectives :

✓ Reactivate core Python syntax (if/else, loops, etc.) and data structures (lists, tuples,
dictionaries).
✓ Reinforce function creation and usage, including lambda functions.

Exercise 1: If/Else, While, For Loops


1. Create a text file (e.g., grades.txt) with student names and their corresponding grades
(e.g., "Farid,18.50\nSalim,14.75\nAhmed,19.22\n..."). Each line represents a student.
2. Calculate the average grade using a for loop to iterate through the grades list.
3. Use if/else statements to determine the number of students who passed (grade >= 10.0)
and failed (grade < 10.0).
4. Print the average grade, the number of passing students, and the number of failing
students.
5. Rewrite each of the previous solutions as a separate function, then test them all
thoroughly.
6. Explain the importance of lambda functions in Python programming, including a code
example. Apply this concept to a previous question.
Exercise 2: Functions and Grade Categorization (Functions/Variables)
1. Create a function called categorize_grade(grade) that takes a numerical grade as input and
returns a letter grade based on the following scale:

▪ [18 – 20]: "A" ▪ [14 – 16[: "C" ▪ [10 – 12[ : "E"


▪ |16 – 18]: "B" ▪ [12 – 14[ : "D" ▪ Below 10: "F"

2. Use a for loop to iterate through the grades list. For each grade, call the categorize_grade()
function to get the letter grade.
3. Store the letter grades in a new list called letter_grades.
4. Print the student names, numerical grades, and letter grades in a formatted table. You can
use string formatting or f-strings for this.
Exercise 3: Data Organization and Lookup (Lists, Tuples, Dictionaries)
1. Create a dictionary called student_data where the keys are student names and the values are
tuples containing the numerical grade and the letter grade. For example: student_data =
{"Assia": (15.35, "C"), "Amine": (12.58, "D"), ...}.
2. Write another function lookup_print_student(name) If the name exists, print the student's
numerical grade and letter grade, else print an appropriate message.
3. Calculate and print the average grade for each letter grade category (A, B, C, D, E, F) using the
student_data dictionary.

© 2024 H.-E. GUERGOUR Page 1 / 1

You might also like