In [1]:
print "Hello Python"
In [2]:
a = "une chaine de caractere"
print a
In [3]:
b = 1
c = 2
print b+c
In [4]:
a = int(raw_input("Entrez un nombre "))
if(a%2==0):
print "Le nombre est pair"
elif(a==0):
print "Vous avez entre 0 qui est pair :)"
else:
print "Le nombre est impair"
In [ ]:
a = 0
while(a!=10):
print a
a+=1
In [ ]:
for i in range(0,10):
print i
In [ ]:
print "Moyenne :"
nb_notes = int(raw_input("Entrez le nombre de notes :"))
compteur = 0
total = 0
while compteur < nb_notes:
total += float(raw_input("Note :"))
compteur +=1
print "Moyenne : "+str(total/compteur)
In [ ]:
import random
print str(random.randint(0,100))
In [ ]:
from random import randint
print str(randint(0,100))
In [ ]:
from random import randint
nombreATrouver = randint(0,100)
userGuess = int(raw_input("Entrez un nombre :"))
tentatives = 1
while userGuess != nombreATrouver:
if(userGuess<nombreATrouver):
print "C'est plus"
else:
print "C'est moins"
tentatives+=1
userGuess=int(raw_input("Entrez un nombre :"))
print "Vous avez trouvé en %s coups"%(tentatives)
In [ ]:
from random import randint
borneInf=0
borneSup=100
coups = 0
aTrouver = randint(borneInf,borneSup)
guess = (borneInf+borneSup)/2
while aTrouver != guess:
if(guess<aTrouver):
print "+"
borneInf=guess
else:
print "-"
borneSup=guess
guess = (borneInf+borneSup)/2
coups +=1
print guess
print "Nombre %s trouve en %s coups "%(guess,coups)
In [1]:
a = "toto"
b = list(a) #On transforme la string en liste
print b
b[1]="u" #On manipule cette liste comme un tableau
print b
b = "".join(b) #On retransforme la liste en string
print b
In [ ]:
In [ ]: