SHARE
TWEET

fill_bag

a guest Aug 20th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def bag_size(bag):
  2.     sum = 0
  3.     for weight in bag:
  4.         sum += weight
  5.     return sum
  6.  
  7. def check_bag(bag, input):
  8.     return bag_size(bag) + input < 100
  9.  
  10. def add_to_bag(bag, input):
  11.     if check_bag(bag, input):
  12.         bag.append(input)
  13.         return True
  14.     else:
  15.         print("The bag would go over 100kg")
  16.         return False
  17.  
  18. def fill(bag):
  19.     new_weight = int(input("enter a weight: "))
  20.     while(add_to_bag(bag, new_weight)):
  21.         new_weight = int(input("enter a weight: "))
  22.     print("The bag is full with weight {}kg".format(bag_size(bag)))
  23.  
  24. if __name__ == "__main__":
  25.     bag = []
  26.     fill(bag)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top