Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bag_size(bag):
- sum = 0
- for weight in bag:
- sum += weight
- return sum
- def check_bag(bag, input):
- return bag_size(bag) + input < 100
- def add_to_bag(bag, input):
- if check_bag(bag, input):
- bag.append(input)
- return True
- else:
- print("The bag would go over 100kg")
- return False
- def fill(bag):
- new_weight = int(input("enter a weight: "))
- while(add_to_bag(bag, new_weight)):
- new_weight = int(input("enter a weight: "))
- print("The bag is full with weight {}kg".format(bag_size(bag)))
- if __name__ == "__main__":
- bag = []
- fill(bag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement