Social Icons

Friday, August 16, 2019

Python practice : Exercises with solution- part 1- exercise on strings and lists

Python training provided by programmers (les programmeurs)

Python practice : Exercises with solution

Part 1- exercises on strings and lists

Exercise 1 || Solution

Write a program in Python language that asks the user to enter their name and display their name with a welcome message!

Exercise 2 || Solution

Write a program in Python that asks the user to enter two numbers a and b and display their sum: a + b.

Exercise 3 || Solution 

Write a program in Python that asks the user to enter two numbers a and b and to display their maximum

Exercise 4 || Solution

Write a program in Python language that displays the first 100 integers

Exercise 5 || Solution

Write a program in Python language that asks the user to enter their integer number and to display it if this number is even or odd

Exercise 6  ||  Solution

Write a program in Python language that asks the user to enter their age and display the message "You're Major!" If the age typed is greater than or equal to 18 and the message "you are under age!" If the typed age is less than 18

Exercise 7  ||  Solution

Write a program in Python that asks the user to enter 3 numbers x, y, and z and display their maximum

Exercise 8  ||  Solution

Write a program in Python that asks the user to enter an integer n and display the value of the sum 1 + 2 + ... + n =

Exercise 9  ||  Solution

Write a program in Python that asks the user to enter an integer n and display it n!

Exercise 10  ||  Solution

Write a program in Python that asks the user to enter the radius of a circle and return the area and perimeter.

Exercise 11  ||  Solution

Write a program in Python that asks the user to enter an integer n and display all the divisors of that number.

Exercise 12  ||  Solution

1) - Write a program in Python that asks the user to enter an integer n and display the multiplication table of that number.
2) - Improve the program so that it displays multiplication tables of all numbers between 1 and 9

Exercise 13   ||  Solution

Write a program in Python language that asks the user to enter two integers a and b and to display the quotient and the remainder of the Euclidean division of a by b.

Exercise 14   ||  Solution

Write a program in Python language that asks the user to enter an integer n and display it if this number is perfect square or not

Exercise 15   ||   Solution

Write a program in Python language that asks the user to enter an integer n and display it if this number is prime or not

Exercise 16.   ||  Solution

Write a program in Python language that asks the user to enter a string s and then display him all the characters contained in this string.
Example for s = "Python", the program displays the characters:
P
y
t
h
o
n

Exercise 17  ||  Solution

Write a program in Python to display for a given string the number of occurrences of each character in the string. Example for the string s = "Python.org" the program must display: The character: "P" appears once in the string s The character: "y" appears once in the string s The character: "t" figure 1 time in the string s The character: "h" appears once in the string s The character: "o" appears twice in the string s The character: "n" appears once in the string s The character: " . "figure 1 time in the string s The character:" r "figure 1 time in the string s The character:" g "figure 1 time in the string s

Exercise 18  ||  Solution

Write a program in Python that asks the user to enter a string s and return a message indicating whether the string contains the letter 'a' by indicating its position on the string. Example if the user types the string s = 'language' the program returns: The letter 'a' is in position: 1 The letter 'a' is in position: 5

Exercise 19   ||   Solution

Write a program in Python that lists the strings that make up the list l = ["laptop", "iphone", "tablet", "printer", "Ipad"] by indicating the length of each string.

Exercise 20   ||   Solution

Write a program in Python language, to exchange the first and last characters of a given string.

Exercise 21  ||  Solution

Write a program in Python language, which allows you to count the number of vowels in a given string. Example for the string s = 'anticonstitutionally' the program must return the following message: The string anconstitutionally has 9 vowels.

Exercise 22  ||  Solution

Write a program in Python, which returns the first word of a given text. Example for the text: t = 'Python is a wonderful programming language', the program must return Python

Exercise 23  ||  Solution

Write a program in Python language that asks the user to enter the name of a file and return the extension. Example if the user enters coursPython.pdf the program returns the message "The file extension is .pdf".

Exercise 24   ||  Solution

A palindrome is a word whose order of letters remains the same whether it is read from left to 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 return it if it is a palindrome or not?

Exercise 25  ||  Solution

Write a program that asks the user to enter a word and return the opposite. Example if the user enters the word python, the program returns nohtyp.

Exercise 26  ||  Solution

Write a program that asks the user to enter a text and return all words beginning with the letter a.

Exercise 27  ||  Solution

Write a program in Python as a function that calculates the sum of elements in a list of numbers. And another that multiplies all the elements of a list of numbers

Exercise 28  ||  Solution

Write a Python program that tests whether a list is empty or not. Same question for a string of characters.

Exercise 29  ||  Solution

Write a Python program that removes duplicate items from a list.

Exercise 30  ||  Solution

Write a function in Python that allows to compare two lists and to tell us if these two lists have a common value or not.

Exercise 31  ||  Solution

Write a Python program that retrieves the list of even integers and the list of odd integers from a list of numbers.

Exercise 32  ||  Solution

Write a program in Python that returns all the lists obtained by swapping the terms of a given list.

Exercise 33  ||  Solution 

Write a program in Python that asks the user to enter a string and display the characters of even index. Example for the string s = "Python", the program returns "Pto".

Exercise 34  ||  Solution

Given the list of student notes: notes = [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  another list that contains only the notes above the average ( notes > = 10 ).

 Exercise 35  ||  Solution

Write a program in Python that allows you to transform a given url address into a link.

Exercice36  ||  Solution

Write a program in Python to delete multiple spaces in a string

Exercise 37  ||  Solution

Write a Python program that creates a list whose elements are the words common to two strings s1 and s2.

Exercise 38 ||  Solution

Write a Python program to find the longest word on a string

 Exercise 39 ||  Solution

Write a Python program that counts the number of words on a string

 Exercise 40 ||  Solution

Write a Python program that allows you to swap the first and the last word. Example if s = "Python is a programming language", the program returns the string s2 = "programming is a Python language"


Younes Derfoufi
my-courses.net

No comments:

Post a Comment

Category Of Mobile Courses

Actualités (644) Adsense (1) Affiliation (1) Algebraic Topology (1) Algorithmic (1) all-news (30) Android (5) Android app without code (4) Android Apps (97) Android Development (4) Android download (2) Android OS (3) AngularJS (1) Automata theory and formal language (5) C programming (5) Category and Functor (8) CMS (3) Computer Glossary (18) Create Mobile App With Ionic Framework (2) CSS (2) Developpement Java (13) Differential Geometry (1) dropshiping (26) Earn Money by Internet (4) Emplois (23) Framework php (2) Fraud (2) HTML (7) Java For Beginners (10) Javascript (12) Kotlin Programming Language (8) Kotlin For Mobile Android (1) Linux Download (2) Marketing (5) Mobile (3) Mobile Courses (4) Mobile Marketing (4) MoneyGram (1) News (721) Node.js (5) Open Source (1) Photoshop (1) Protect Computer (1) Python (30) Python BeautifulSoup (1) Python For Data Science (2) Python-Exercises (55) Référencement (2) Script PHP (2) Security (6) SEO (1) Snipping Tool: Faq (1) Social Networks (1) Source Code (1) Statistics With SPSS (2) Surveillance Software (1) Travail à domicile (6) Tutoriels php en vidéos (2) Tutoriels-MySql (6) tutoriels-php (19) Utilitaires (1) VPS (1) Web Hosting (1) Webcam (1) Webmarketing (11) Western Union (1) Windows 10 (1) Windows 7 (4) Windows 7 Faq (2) Windows 8 (1) Windows Accessories (1) Windows Download (8) Windows Drivers (1) Windows Fonts (1) Windows Power Shell (2) Windows Registry (2) Windows Security (18) Windows Software (2) Windows Spyware (2) Windows utilities (3) Windows Virus (2) Windows Vista (3) Windows Wireless (1) Windows xp (1)
 

Sample text

Sample Text

 
Blogger Templates