Skip to content

Instantly share code, notes, and snippets.

@fabian57
Last active August 29, 2015 14:11
Show Gist options
  • Save fabian57/f84ed3e5ebb36d0f0bc1 to your computer and use it in GitHub Desktop.
Save fabian57/f84ed3e5ebb36d0f0bc1 to your computer and use it in GitHub Desktop.
pond = input("Diameter of the pond? ")
water_lily = input("Initial diameter of the water lily? ")
growth = input("Daily growth? ")
day = 0
while water_lily < pond:
day += 1
water_lily *= growth
print "On day %s: %s" % (day, water_lily)
print"The pond is smothered!"
@laowantong
Copy link

Parfait!

Tu en as bavé pour la ligne 8... En fait, on écrit généralement ce genre de choses en utilisant une chaîne de format (printf en C). En Python 2.7, l'opérateur % est surchargé en:

     print "On day %s: %s" % (day, water_lily)

J'introduirai ça officiellement plus tard, mais tu peux bien sûr l'utiliser d'ici là si tu veux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment