import random
class Apple:
def __init__(self, weight):
self.weight = weight
class Packaging:
apple_count = 0
total_weight = 0
def __init__(self, apple):
Packaging.apple_count += 1
Packaging.total_weight += apple.weight
if Packaging.total_weight > 300:
Packaging.apple_count -= 1
Packaging.total_weight -= apple.weight
def __str__(self):
message = "Apple Count: {}, Total weight: {}".format(Packaging.apple_count, Packaging.total_weight)
return message
apple_weight_list =[random.uniform(0.2,0.5) for x in range(1000)]
apple_list = [Apple(i) for i in apple_weight_list]
for apple in apple_list:
package = Packaging(apple)
print(package)
Created
January 8, 2021 10:26
-
-
Save akirap3/6bcfe1425a777fdd86abc2a986bca2c8 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment