python
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
n = 3+4
|
||||
n = n + 1
|
||||
m = 3*n
|
||||
# affectations d'entier
|
||||
# rien ne s'affice à l'exécution
|
||||
# mais n et m ont bien chacun une valeur
|
||||
|
||||
print(n)
|
||||
# Pour afficher la valeur de n
|
||||
print(3*5)
|
||||
|
||||
# p = input("Quelle valeur veux tu ? ")
|
||||
|
||||
p1 = int(input("Quelle valeur veux tu ? "))
|
||||
print("La valeur de p1 est", p1)
|
||||
|
||||
|
||||
# Ecrire une suitre de comamnde qui
|
||||
# demande votre prénom, votre nom, votre age et affiche
|
||||
# "Pierre Valarcher tu as XXX ans"
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Ecrire une suitre de commande qui
|
||||
# demande votre prénom, votre nom, votre age et affiche
|
||||
# "Pierre Valarcher tu as XXX ans"
|
||||
|
||||
prenom = input("Votre prénom : ")
|
||||
nom = input("Votre nom : ")
|
||||
age = int(input("Votre age : "))
|
||||
|
||||
print(prenom, nom, "tu as", age, "ans")
|
||||
|
||||
phrase = prenom + ' ' + nom + ", tu as " + str(age) + " ans"
|
||||
# + est la concaténation sur les chaines de caractères
|
||||
|
||||
prenom = "Paul"
|
||||
print(prenom, nom, "tu as", age, "ans")
|
||||
|
||||
|
||||
if age <= 40:
|
||||
print("tu es jeune")
|
||||
else:
|
||||
print("tu es plutot vieux/vieille")
|
||||
@@ -0,0 +1,19 @@
|
||||
# Entrer un entier compris entre 0 et 20 (note)
|
||||
# et afficher la mention associée
|
||||
# si l'entier n'est pas compris entre 0 et 20 ne rien ecrire
|
||||
|
||||
note = int(input("Entrer une note [entre 0 et 20] : "))
|
||||
|
||||
if (note >= 10) and (note < 12):
|
||||
mention = "Passable"
|
||||
elif (note >=12) and (note < 14):
|
||||
mention = "Assez Bien"
|
||||
elif note>=14 and note < 16:
|
||||
mention = "Bien"
|
||||
elif note >= 16:
|
||||
mention = "Très Bien"
|
||||
|
||||
if note >=10 and note <= 20:
|
||||
print ("La note ", note, "correspond à la mention ", mention)
|
||||
elif note>=0 and note<10:
|
||||
print ("Echec")
|
||||
@@ -0,0 +1,39 @@
|
||||
# Display the following message:
|
||||
#**************
|
||||
# 1) Square
|
||||
# 2) Triangle
|
||||
|
||||
# Enter a number :
|
||||
#**************
|
||||
|
||||
|
||||
# If the user enters 1, then it should ask them for the length of one of its sides and display the area. If they select 2, it should ask for the base and height of the triangle and display the area. If they type in anything else, it should give them a suitable error message.
|
||||
|
||||
# square area == side*side
|
||||
# triangle area == (base*height)/2
|
||||
|
||||
for i in range(0,15):
|
||||
print('*', end='')
|
||||
print("\n1) Square")
|
||||
print("2) Triangle")
|
||||
for i in range(0,15):
|
||||
print('*', end='')
|
||||
v = int(input("\n\nEnter a number : "))
|
||||
|
||||
if v==1:
|
||||
side = int(input("Enter a side : "))
|
||||
area = side*side
|
||||
elif v==2:
|
||||
height = int(input("Enter a height : "))
|
||||
base = int(input("Enter a base: "))
|
||||
area = (height*base)/2
|
||||
else:
|
||||
print("Input error (waiting for 1 or 2)!!!!!")
|
||||
|
||||
if v==1:
|
||||
print("The area of the square is", area)
|
||||
elif v==2:
|
||||
print("The area of the triangle is", area)
|
||||
|
||||
|
||||
print("toto".title())
|
||||
@@ -0,0 +1,30 @@
|
||||
# Display the following message:
|
||||
#**************
|
||||
# 1) Square
|
||||
# 2) Triangle
|
||||
|
||||
# Enter a number :
|
||||
#**************
|
||||
|
||||
|
||||
# If the user enters 1, then it should ask them for the length of one of its sides and display the area. If they select 2, it should ask for the base and height of the triangle and display the area. If they type in anything else, it should give them a suitable error message.
|
||||
|
||||
# square area == side*side
|
||||
# triangle area == (base*height)/2
|
||||
|
||||
|
||||
print("***************")
|
||||
print("1) Square")
|
||||
print("2) Triangle")
|
||||
print("***************")
|
||||
v = int(input("Enter a number : "))
|
||||
|
||||
if v==1:
|
||||
square = int(input("coté : "))
|
||||
area = square*square
|
||||
elif v==2:
|
||||
height = int(input("hauteur : "))
|
||||
base = int(input("base : "))
|
||||
area = (height*base)/2
|
||||
|
||||
print("L'aire est", area)
|
||||
@@ -0,0 +1,7 @@
|
||||
name = input("Votre nom : ")
|
||||
hello = "Bonjour " + name
|
||||
print (hello)
|
||||
print ("Bonjour", name)
|
||||
name = name+name
|
||||
print ("Bonjour", name)
|
||||
print (hello)
|
||||
@@ -0,0 +1,57 @@
|
||||
# Boucle
|
||||
|
||||
for valeur in range(1, 10, 2): # "valeur" variable locale à la boucle, on parcours de 2 en 2
|
||||
print(valeur)
|
||||
|
||||
print(valeur)
|
||||
|
||||
|
||||
for valeur in range(30, 10, -3):
|
||||
print(valeur)
|
||||
|
||||
compteur = 0 # initialisation du compteur
|
||||
for i in "toto est malade":
|
||||
if i != ' ':
|
||||
compteur = compteur + 1 # on incrémente un compteur
|
||||
|
||||
print("nombre de lettre", compteur)
|
||||
|
||||
|
||||
# Un programme qui demande une phrase et qui renvoie le nombre de voyelles
|
||||
# Et le nombre de symboles qui ne sont pas des voyelles
|
||||
|
||||
cpt = 0
|
||||
cpt2 = 0
|
||||
phrase = input("Ecrire une phrase : ")
|
||||
for i in phrase.lower(): # Pour mettre tout en minuscule
|
||||
if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u' or i == 'y':
|
||||
cpt = cpt + 1
|
||||
else:
|
||||
cpt2 = cpt2 + 1
|
||||
|
||||
print("Il y a", cpt, "voyelle(s) dans la phrase: ", phrase)
|
||||
print("Il y a", len(phrase)-cpt, "symboles autres que voyelles dans la phrase: ", phrase)
|
||||
# print("Il y a", cpt2, "symboles autres que voyelles dans la phrase: ", phrase)
|
||||
|
||||
cpt = 0
|
||||
voyelles = ['a', 'e', 'i', 'o', 'u', 'y'] # on définit une sorte d'ensemble de valeurs
|
||||
for i in phrase.lower():
|
||||
if i in voyelles: # in veut dire "appartient"
|
||||
cpt = cpt + 1
|
||||
|
||||
|
||||
# Demander 4 notes entre 0 et 20 et calculer la moyenne de ces 4 notes
|
||||
|
||||
somme = 0
|
||||
for i in range(1,5):
|
||||
note = float(input("Entrer une note entre 0 et 20 : "))
|
||||
somme = somme + note
|
||||
|
||||
moyenne = somme / 4
|
||||
|
||||
print("La moyenne est", moyenne)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# module math
|
||||
|
||||
import math
|
||||
|
||||
math.pi
|
||||
math.sqrt(5) # racine carré
|
||||
|
||||
f = float(input("Valeur reel : "))
|
||||
@@ -0,0 +1,17 @@
|
||||
# operations sur les chaines de caractères
|
||||
|
||||
w = "toto est malade"
|
||||
print("La longueur de la chaine", w, "est",len(w)) # len (w) la longueur du mot
|
||||
print(w.capitalize()) # premiere lettre en majuscule
|
||||
print(w.upper()) # met en majuscule
|
||||
print(w.lower())
|
||||
print(w.title()) # met en majuscule les premieres lettres des mots
|
||||
|
||||
|
||||
print("toto".title())
|
||||
|
||||
w2 = " mais il est content!"
|
||||
|
||||
print(w+w2) # concaténation
|
||||
|
||||
print(w[3:9]) # affiche les caracteres en 4eme position jusqu'à la 8eme incluse
|
||||
Reference in New Issue
Block a user