Series of Python Exercises
Series of Python Exercises
Exercise 1
Write a program in Python that asks the user to enter their name
and to display his name with a welcome message!
Exercise 2 ||
Write a program in Python that asks the user to enter two numbers a and
and to display their sum: a + b
Exercise 3 ||
Write a program in Python that asks the user to enter two numbers a and
and to display their maximum.
Exercise 4 ||
Write a program in Python that displays the first 100 integers
Exercise 5 ||
Write a program in Python that asks the user to enter their
integer and display whether this number is even or odd
Exercise 6 ||
Write a program in Python that asks the user to enter their age and
to display the message "you are of legal age!" if the entered age is greater than or equal to
You are a minor!
Exercise 7 ||
Write a program in Python that asks the user to enter 3 numbers x, y, and z
and to show them their maximum
Exercise 8 ||
Write a program in Python that asks the user to enter an integer.
and display the value of the sum 1 + 2 + … + n =
Exercise 9 ||
Write a program in Python that asks the user to enter an integer.
and display n!
Exercise 10 ||
Write a program in Python that asks the user to enter the radius of a
Circle him to send back the area and the perimeter.
Exercise 11 ||
Write a program in Python that asks the user to enter an integer.
and to display all the divisors of this number.
Exercise 12 ||
1) - Write a program in Python that asks the user to enter a number
an integer and display the multiplication table of that number.
1
TPPython:CorrectedexercisesinPythonalgorithms:thebasics
Prof: Nidhal Trabelssi 2020
2) – Improve the program so that it displays the multiplication tables of all the
numbers between 1 and 9
Exercise 13 ||
Write a program in Python that asks the user to enter two
integer numbers a and b and display the quotient and the remainder of the division
Euclidean of a by b.
Exercise 14
Write a program in Python that asks the user to enter
Integer number n and display whether this number is a perfect square or not.
Exercise 15
Write a program in Python that asks the user to enter a
integer number n and show whether this number is prime or not.
Exercise 16 ||
Write a program in Python that allows you to browse and display the
characters of a variable of the string type. Example for s = 'Python',
the program poster the characters :
P
y
t
h
o
n
Exercise 17 ||
Write a program in Python to display for a string
data, the number of occurrences of each character in the string. Example for the
string s = "Python.org" the program should display:
The character : ” P ” figure 1 times in the chain s
The character : ” y ” figure 1 times in the chain
The character : ” t ” figure 1 times in the chain s
The character : ” h ” figure 1 times in the chain s
The character : ” o ” figure 2 times in the chain s
The character : ” n ” figure 1 times in the chain
The character : ” . ” figure 1 times in the chain s
The character : ” r ” figure 1 times in the chain
Thecharacter:”g”appears1timeinthestrings
Exercise 18 ||
Write a program in Python that asks the user to enter a string
character s and send him a message indicating whether the string contains the letter 'a'
while indicating its position in the string. For example, if the user types the string s =
‘language’ the program returns: The letter ‘a’ is located at position: 1 The letter
‘a’ is located at position: 4
Exercise 19 ||
Write a Python program that lists the strings that make up the list.
l = [“laptop”, “iphone”, “tablet”] tout en indiquant la longueur de chaque chaine.
Exercise 20
2
TPPython:CorrectedexercisesinPythonalgorithms:thebasics
Prof: Nidhal Trabelssi 2020
Write a program in the Python language that swaps the first and last.
character of a given string.
Exercise 21 ||
Write a program in Python that counts the number of vowels.
in a given chain. Example for the chain s='anticonstitutionally'
The chain unconstitutionally
has 10 vowels.
Exercise 22 ||
Write a program in Python that returns the first word of a
yougaveyourself.Exampleforthetext:Python is a wonderful programming language
programmingthe program must return Python
Exercise 23 ||
Write a program in Python language that asks the user to enter their name
of a file and return its extension. Example if the user inputs
coursPython.pdf the program returns the message "The file extension is .pdf"
».
Exercise 24 ||
An unpalindrome is a word whose order of letters remains the same when read from left to right.
right or from right to left. For example: 'laval', 'radar', 'sos'… are
palindromes. Write a program in Python that asks the user to enter a
word and send it back to him to determine if it is a palindrome or not?
Exercise 25 ||
Write a program that asks the user to enter a word and
let's return the inverse. For example, if the user enters the word python, the program will
typeonihvereno.
Exercise26|
Write a program that asks the user to input a text and returns it.
all the words starting with the letter a.
Exercise 27 ||
Write a program in Python in the form of a function that calculates the sum of
elements of a list of numbers. And another one that allows to multiply all the elements
of a list of numbers.
Exercise 28 ||
Write a Python program that tests if a list is empty or not. The same question for
a string.
Exercise 29 ||
Write a Python program that allows you to remove duplicate elements from a
list.
Exercise 30 ||
Write a function in Python that allows comparing two lists and indicating
whether these two lists have a common value or not.
Exercise 31
3
TPPython:CorrectedexercisesonPythonalgorithms:thebasics
Nidhal Trabelssi 2020
Write a Python program that extracts the list of even integers and the list
odd integers from a list of numbers.
Exercise 32 ||
Write a program in Python that returns all the lists obtained by permuting the
terms of a given list.
Exercise 33 ||
Write a program in Python that asks the user to input a string.
characters and display the characters at even indices. Example for the string s =
"Python", the program returns 'Pto'.
Exercise 34 ||
Given the list of students' scores: scores = [12, 04, 14, 11, 18, 13, 07,
10, 05, 09, 15, 08, 14, 16]Write a Python program that allows you to extract from
this list and create another list that contains only the grades above the
average ( the grades >= 10 )
Exercise 35 ||
Write a program in Python that allows you to transform a URL entered in
keyboard in a link
Exercise36 ||
Write a Python program to remove multiple spaces in
a chains
Exercise 37 |
Write a Python program that allows grouping common words in a list.
to two chains s1 and s2.
Exercise 38
Write a Python program that allows you to search for the longest word in a
chains
Exercise 39 ||
Write a Python program that counts the number of words in a
chains. It is assumed that the text is well-formed (a space after each punctuation
and no space before punctuation)
Exercise 40
Write a Python program that swaps the first and the last word.
For example, if s="Python is a programming language", the program returns
programming is a language of Python
is well trained ( a space after each punctuation and no space before the
punctuation)
Exercise 41 ||
Create a Python function called DivisibleNumber that applies to a list of
names and an entire number n, and which returns the number of elements in the list that
are divisible by n.
Exercise 42 ||
4
TPPython:CorrectedexercisesinPythonalgorithmics:thebasics
Professor: Nidhal Trabelssi 2020
Exercise 46
Write a function in Python that provides the list of digits of a
number written in base 10 without converting the number to a string and without using any
predefined function.
Exercise 47|
Write an algorithm in Python that returns a list formed of
common words in two texts. For example, if T1 = "Python is a programming language"
programming" and T2 = "Python is object-oriented", the program should return the
list of common words L = [‘Python’, ‘is’].
5
TPPython:CorrectedexercisesinPythonalgorithms:thebasics