Solution Exercise 7: maximum of three numbers in Python
Exercise 7 Write a Python algorithm that asks the user to enter 3 numbers x, y and z and display their maximum without using any predefined function.
Cours Python Complet + 500 Exercices Avec Solutions
Exercise 7 Write a Python algorithm that asks the user to enter 3 numbers x, y and z and display their maximum without using any predefined function.
Exercise 12 By using the sort() method, write an algorithm in python as a function which takes a list L of numbers as a parameter and which returns the tuple (min , max) formed from the minimum and the maximum of the list.
Exercise 12 . 1) – Write a program in Python that asks the user to enter an integer n and display him the multiplication table of this number. 2) – Improve the program so that it displays the multiplication tables of all the numbers between 1 and 9
Exercise 11 Write an algorithm in python as a function which takes as parameters a tuple (L, n) formed by a list L of numbers and an integer n and which returns the list obtained from L by multiplying its elements by n . Example if L = [13, 11, 7, 25] and n =…
Exercise 10 Write an algorithm in python as a function which takes as a parameter a tuple (L, a) formed by a list L and an element 'a' and which returns the position of the element 'a' in the list L. The function must return -1 if the element 'a' is not in the list.
Exercise 8 Write an algorithm in python that returns the average of the terms of a list of numbers.
Exercise 7 Write a Python program that returns the list of divisors of a given integer. Example if n = 36 , the algorithm returns the list [1, 2, 3, 6, 9, 18 , 36]
Exercise 16 Write a python program to display all characters of a string variable. Example for s = "Python", the program displays the characters: P y t h o n Solution (First method)
1 2 3 4 5 6 7 8 9 | # Ask the user to enter a string variable s s = input("Enter a string of characters s: ") # get the length of s n = len(s) # display all characters of s for i in range(0, n): print(s[i]) |
Solution (second method)
1 2 3 4 5 6 | # Ask the user to enter a string variable s s = input("Type a string of characters s: ") # display all characters of s for x in s: print(x) |
Younes Derfoufi CRMEF OUJDA
Exercise 10 Write a python program that asks the user to enter the radius of a circle and return the area and perimeter.
Exercise 3 Write a python algorithm as a function which takes a list l as parameters and returns a tuple of two lists (l_even, l_odd) where l_even is made up of the elements of l with an even index and l_old is made up of the elements with an odd index. Example: if: L =…
Exercise 5 Given a list L of integers, write a Python program that returns the sum of the elements of L.
Exercise 6 Write a Python algorithm that asks the user to enter their age and display the message "you are major!" if the typed age is greater than or equal to 18 and the message "you are a minor!" if the typed age is less than 18