0% found this document useful (0 votes)
16 views

Code 2

Uploaded by

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

Code 2

Uploaded by

room free2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

from math import *

import numpy as np
import matplotlib.pyplot as plt
def exercice1():
for i in range(0,11):
print(5*i)
def exercice2():
for i in range(1,11):
print("table de multiplication de ",i)
for j in range(0,11):
print(i," x ",j ," = ",i*j)
def exercice3():
a = int(input("nombre 1 : "))
b = int(input("nombre 2 : "))
q=0
while(a>=b):
a -= b
q+=1
print("quotient entier : ", q)
print("reste : ", a)
def exercice4():
a = float(input("a = "))
n=0
#n = floor(log(a)/log(2))+1
# #print(n)
while(2**n <= a):
n += 1
print(n)
def exercice5():
x = int(input("x = "))
n = int(input("n = "))
a=1
for i in range(0,n):
a *=x
print(a)
def exercice6():
n = int(input("n = "))
S=0
for i in range(0,n):
S += 1/i
print(S)
def exercice7():
n = int(input("n = "))
f=1
for i in range(1,n+1):
f*=i
print(f)
def exercice8():
a = float(input("n = "))
n=0
while(2**n <= a):
if(2**(n+1)>a):
break
n += 1
print(n)
def exercice9():
N = input("nombre : ")
c = input("chiffre : ")
o=0
for i in range(len(N)):
if(c == N[i]):
o+=1
print(o)
def exercice10():
n = int(input("Nombre : "))
S = [1]
b=0
D=2
while(D<=sqrt(n)):
if(D == sqrt(n)):
S.append(D)
elif(n%D==0):
S.append(D)
S.append(n//D)
D +=1
for i in range(len(S)):
b += S[i]
if(n==b):
print("le nombre est parfait")
else:
print("le nombre n'est pas parfait")
def exercice11():
x = int(input("x = "))
if(floor(sqrt(x))==sqrt(x)):
print(x,"est un carré parfait")
else:
print(x,"n'est pas un carré parfait")
def exercice12():
n = int(input("nombre : "))
p = True
for i in range(2,n):
if(n%i==0):
print(n,"n'est pas premier")
p = False
break
if(p==True):
print(n,"est premier")
def exercice13():
n = int(input("n = "))
Un = []
Un.append(1)
Un.append(2)
if(n>1):
for i in range(2, n+1):
Un.append(Un[i-1] + 6*Un[i-2])
print(Un[n])
def exercice14():
N= int(input("N = "))
if(N<0):
print(len(str(N))-1)
else:
print(len(str(N)))
def exercice15_isqrt1(n):
p=1
while(p**2<=n):
if((p+1)**2>n):
print(p)
break
else:
p+=1
def exercice16():
max_n = 0
for i in range(0,10):
n = int(input())
if(n>max_n):
max_n = n
print("max = ",max_n)
def exercice17():
F = True
prev_n = 0
for i in range(0,20):
n = int(input())
if(n>=prev_n):
prev_n = n
else:
F = False
if(F==0):
print("Les entiers ne sont pas triés dans un ordre croissant.")
else:
print("Les entiers sont triés dans un ordre croissant.")

def exercice18_1(i,j):
for x in range(i,j+1):
if(x<j):
print(x ,end='-')
else:
print(x ,end='\n')
def exercice18_2(i,j):
for x in range(i,j+1):
if(x<j):
if(x%7!=0):
if((x+1)%7!=0):
print(x ,end='-')
else:
print(x ,end='')
else:
if(x%7!=0):
print(x ,end='\n')
else:
print('\n')

def exercice19_triangle1(n):
for i in range(n):
print('*'*(i+1))
def exercice19_triangle2(n):
for i in range(n):
print('*'*(n-i))
def exercice19_pyramide1(n):
exercice19_triangle1(n)
exercice19_triangle2(n-1)
def exercice19_pyramide2(n):
for i in range(1,n+1):
print(' '*(n-i), end='')
print('* '*(i))
def exercice21():
n =input()
s=0
for i in range(len(n)):
s += int(n[i])**3
if(s==int(n)):
print('ARMSTRONG')
else:
print('non ARMSTRONG')
def exercice22():
n = int(input())
s=''
while(n!=0):
n = n//2
s += str(n%2)
print(s)
def exercice23():
s = input()
n=''
for i in range(len(s)):
if(s[i] != '0' and s[i] != ' '):
n+=s[i]
print(n[::-1])
def exercice24():
a = int(input("a = "))
b = int(input("b = "))
c,d = a,b
a, b = max(a,b),min(a,b)
while(True):
if(a%b==0):
print("le pgcd est ", b)
break
else:
a,b =b , a%b
print("le ppcm est ", int((c*d)/b))
def exercice25():
U = [0,1]
n=int(input("n = "))
for i in range(2,n+1):
U.append(U[i-1]+U[i-2])
print(U[n])
def f(x):
return x**2-4
def ins(x):
return x*2 +2
def exercice20():
a=2
b=4
while(a<b):
if(f((a+b)/2)==0):
print("la solution est ", (a+b)/2)
break
elif(f((a+b)/2)>0):
b = (a+b)/2
else:
a = (a+b)/2
def exercice20plt():
x = np.arange(0,5)
y = f(x)
c = np.arange(0,5)
b=ins(c)
plt.plot(x,y)
plt.axhline(0,color="red")
plt.axvline(2,color="red")
plt.grid()
plt.show()

You might also like