Solution Exercise 7: Python algorithm that returns the list of divisors of a number
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]
Cours Python
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
Exercise 13 Write a program program which asks the user to enter two integers 'a' and 'b' and display the quotient and the remainder of the Euclidean division of 'a' by 'b'.
Exercise 5 Write a program in Python language that asks the user to enter an integer number 'n' and display whether this number is even or odd.
Exercise 4 Write a program in Python that displays the first 100 integers
Exercise 3 Write a program in Python that asks the user to enter two numbers a and b and display their maximum, without using the max() function or any predefined function.
Exercise 15 Write a python program that asks the user to enter an integer n and to display whether this number is prime or not.
Exercise 1 Write a python algorithm to display all elements of a given list in two different ways
Exercise 1 || Solution Write a python algorithm to display all elements of a given list by two different ways. Exercise 2 || Solution Write a Python algorithm to swap the first element with the last element of a given list. Example: if L = ["Python", "Java", "C++", "Javascript"], the algorithm returns the list: ["Javascript",…
Python Exercises With Solutions Python Exercises On Strings & Var Exercises On Python Lists
Exercise 2 Write a program in Python that asks the user to enter two numbers 'a' and 'b' and display their sum: 'a + b'
Exercise 1 Write a program in Python language that asks the user to enter their name and display their name with a welcome message!