Academic Year 2025 – 2026
Ibn Tofail University Semester 1
Faculty of Sciences - Kenitra Module: Intro. to Artificial Intelligence
Masters: IST, ESE, ERHV.
Practical Work (TD) N° 1
Introduction to Python Basics
Professor: H. BEZZOUT
Exercise 1: Area of a Circle
Q1: Translate this algorithm into Python language:
S = πr2
• Input: The radius of a circle r.
O r
• Output: The area of the circle S = π × r2 .
Exercise 2: Converting Seconds to Hours, Minutes, Seconds
Q1: Write a Python program HoursMinutesSeconds to solve the following problem:
• Input: An integer n (representing a quantity of seconds).
• Output: The conversion of this number into hours, minutes, and seconds.
For example, the number 8000 is equivalent to 2 hours, 13 minutes, and 20 seconds.
Exercise 3: Collision Detection
Q1: Analyze the following problem and write a Python pro-
gram to solve it:
• Input: Two circles C1 and C2 , each specified by the X r2
and Y coordinates of its center, and its radius r. d C2 (x2 , y2 )
• Output: True if the intersection of C1 and C2 is not r
empty (the circles are colliding), and False otherwise. C11(x1 , y1 )
Note: This algorithm is commonly used for collision detection
in video games.
Page 1
Academic Year 2025 – 2026
Ibn Tofail University Semester 1
Faculty of Sciences - Kenitra Module: Intro. to Artificial Intelligence
Masters: IST, ESE, ERHV.
Exercise 4: Parity Check
Q1: Write a Python program isEven to solve the following problem:
• Input: An integer n.
• Output: True if n is even, and False otherwise.
Exercise 5: Grade Evaluation
Q1: Provide a description of the problem, then write a corresponding Python program to read a
grade, verify if the grade is between 0 and 20, and determine the letter grade (mention) associated
with it:
• Insufficient: Below 10
• Passable: From 10 to 11
• Fairly Good: From 12 to 13
• Good: From 14 to 15
• Very Good: From 16 to 20
Exercise 6: Calculator Simulator
12.5 + 7
Q1: Build a Python program that simulates a basic calculator.
The algorithm reads two real numbers and an arithmetic operator 7 8 9 ÷
as inputs, and outputs the result of the calculation. The standard 4 5 6 ×
operators are +, -, * and /. 1 2 3 -
0 . = +
Exercise 7: Factorial Calculation
Q1: Build a Python program to solve the following problem:
• Input: An integer n.
• Output: Its factorial n! = n × (n − 1) × (n − 2) × · · · × 1.
Page 2
Academic Year 2025 – 2026
Ibn Tofail University Semester 1
Faculty of Sciences - Kenitra Module: Intro. to Artificial Intelligence
Masters: IST, ESE, ERHV.
Exercise 8: Multiplication Table
Q1: Write a Python program that takes an integer between 1 and 10 as input and outputs the
multiplication table for that number. For instance, if the input is 7, the program will print:
1 x 7 = 7
2 x 7 = 14
3 x 7 = 21
...
10 x 7 = 70
Exercise 9: Savings Account Calculation
At AHMED’s birth, his grandfather ABDELKADER opens a bank account for him. Then,
on each of AHMED’s birthdays, his grandfather deposits 100 Dh into his account, plus twice
AHMED’s age. For example, when he turns two, his grandfather deposits 104 Dh into the
account.
Q1: Write a Python program to determine the total sum AHMED will have on his n-th birthday.
+102 Dh +104 Dh +106 Dh +(. . . ) Dh
Year 0 Year 1 Year 2 ... Year n
Page 3