Skip to content

Instantly share code, notes, and snippets.

@hlidotbe
Created February 13, 2011 14:11
Show Gist options
  • Save hlidotbe/824708 to your computer and use it in GitHub Desktop.
Save hlidotbe/824708 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Initialise les variables a None
# On ne peut pas utiliser une valeur numérique sinon les comparaisons seront
# incorrectes
min_val = None
max_val = None
# Demande un premier nombre
try:
nombre = raw_input('Entrez un nombre:')
except EOFError:
pass
# Tant que l'utilisateur rentre un nombre on continue
while nombre != '':
# On converti la valeur entrée en "vrai" nombre
nombre = float(nombre)
# Verifie si le nombre est plus petit que min_val ou si min_val est vide
# (premier tour)
if(min_val == None or min_val > nombre):
min_val = nombre
# Verifie si le nombre est plus grand que max_val ou si max_val est vide
# (premier tour)
if(max_val == None or max_val < nombre):
max_val = nombre
# Demande un nouveau nombre
try:
nombre = raw_input('Entrez un nombre:')
except EOFError:
pass
# Affiche les valeurs de min et max
print "Le min est", min_val
print "le max est", max_val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment