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

PW1 python

Uploaded by

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

PW1 python

Uploaded by

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

Ministry of Higher Education and Scientific Research

University of Oum El Bouaghi


Faculty of Exact Sciences and Natural and Life Sciences
Department of Mathematics and Computer Science

Advanced Python Language


1st Master - AI & Data Science

Practical Work 01
(1h 30min) 10 minutes for each exercise

Exercise1. If-Elif-Else: Age Classifier

Write a script that asks the user for their age and prints the following messages based on the
entered value:

 "Child" if the age is less than 13.


 "Teenager" if the age is between 13 and 19.
 "Adult" if the age is between 20 and 64.
 "Senior" if the age is 65 or older.

Exercise 2. Match-Case (Python 3.10+): Day of the Week

Write a script that prompts the user for a number (1 to 7) and prints the corresponding day of
the week using the match-case statement. Handle any input that is not in the range of 1 to 7
by printing an error message.

Exercise 3. For Loop: Sum of Numbers

Write a script that uses a for loop to compute the sum of all numbers from 1 to a user-
provided number (n). Print the sum at the end.

Exercise 4. For Loop with Range: Multiplication Table

Write a script that asks the user for a number and prints the multiplication table for that
number from 1 to 10 using a for loop and range().

Exercise 5. Zip: Pairing Two Lists

Write a script that uses the zip() function to pair two lists of equal length (names and
scores). The script should print each name along with the corresponding score

Page 1 sur 2
names = ["Alice", "Bob", "Charlie"]
scores = [85, 90, 78]

The output should look like:

Alice: 85
Bob: 90
Charlie: 78

Exercise 6. While Loop with Break: Input Validation

Write a script that repeatedly prompts the user to enter a positive integer. If the user enters a
negative number or zero, print an error message and prompt them again. Use break to stop
the loop when a valid input is received.

Exercise 7. Continue: Skip Even Numbers

Write a script that uses a for loop to print all odd numbers between 1 and 20. Use the
continue statement to skip even numbers.

Page 2 sur 2

You might also like