0% found this document useful (0 votes)
30 views2 pages

Phython Exercice

Uploaded by

bizerte2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Phython Exercice

Uploaded by

bizerte2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

word_without_vowels = ""

# Prompt the user to enter a word


# and assign it to the user_word variable.
user_word=input("donner un mot:")
user_word=user_word.upper()

for letter in user_word:


# Complete the body of the loop.
if letter in "AEIUO":
continue
word_without_vowels+=letter
# Print the word assigned to word_without_vowels.
print(word_without_vowels)

%%%%%%%%% code manipulation des listes suppressions


hat_list = [1, 2, 3, 4, 5] # This is an existing list of numbers hidden in the
hat.

# Step 1: write a line of code that prompts the user


# to replace the middle number with an integer number entered by the user.
pos=len(hat_list)//2
hat_list[pos]=int(input("Donner la nouvelle valeur du milieu:"))
# Step 2: write a line of code that removes the last element from the list.
del hat_list[-1]
# Step 3: write a line of code that prints the length of the existing list.
print(len(hat_list))
print(hat_list)

%%%%%%%%%%%%%% pair impair


def is_Even(num):
return num % 2 == 0
while True:
x=int(input ("Donne un entier:"))
# appel de la fonction
#y=is_Even(x)
#print(y)

#deuxieme facon
if is_Even(x):
print(x,"est pair")
else:
print(x,"est impair")

%%%%%%%%%%%% somme d'une liste


def somme_lst(my_list):
s=0
for element in my_list:
s=s+element #s=s+element
return s
lst=[10,2,5,0]
somme=somme_lst(lst)
print("la somme de la liste est :=", somme)

%%%%%%%% nombre premiers dans une liste


def is_Prime(num):
for i in range (2, num//2):
if num%i==0:
return False
return True

lst=[10,11,5,48,13,17,22]
for element in lst:
if is_Prime(element):
print(element, end="|")

%%%%% calcul factoriel


def factoriel(num):
fact=1
for i in range (1,num+1):
fact=fact * i
return fact

print(factoriel(5))

%%%%%%%%%%%%%%calcul factoriels dune liste


def factoriel(num):
if num==0:
return 1
else:
return num*factoriel(num-1)

print(factoriel(5))

lst=[5,4,5,6]
# afficher les factoriels
for element in lst:
print(factoriel(element), end="|")
#modefier le selements de la liste
print ("")
for i in range (len(lst)):
lst[i]=factoriel (lst[i])
print(lst)

%%%%%%%%%%%%% gestion des erreurs


while True:
try:
n=int(input("donner un entier :"))
break
except:
n=int(input("donner un entier :"))

if n%2==0:

print(n, "n est pair")


else:
print(n,"n est impair")

You might also like