Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Created January 2, 2011 23:07
Show Gist options
  • Save zeroeth/762918 to your computer and use it in GitHub Desktop.
Save zeroeth/762918 to your computer and use it in GitHub Desktop.
a two input primed sentinel loop
# A Primed two input loop example
### INITIALIZE
total_cat_age = 0
total_cat_weight = 0
total_cats = 0
print "Enter one or more cats age and weight and . to finish"
### LOOP PRIMER
cat_age_input = raw_input("How old is the cat?: ")
### LOOP
while(cat_age_input != "."):
cat_weight_input = raw_input("How much does the cat weigh?: ")
total_cats += 1 # same as total_cats = total_cats + value
total_cat_age += int(cat_age_input)
total_cat_weight += int(cat_weight_input)
cat_age_input = raw_input("How old is the cat?: ")
### SUMMARY
print "You have {} cats with {} years of combined fluffiness that weigh {} pounds all together".format(total_cats, total_cat_age, total_cat_weight)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment