ltcy wrote:A company builds towers with bricks. The company can build two types of towers: impressive and regular. It takes the company 1024 bricks to build impressive towers and 256 bricks to build regular towers. The company makes the most gain by building impressive towers: CDN$10000 each. Regular towers produce less gain but still some: a regular tower provides the company CDN$ 2000 gain. On the other hand, the company loses CDN$ 20 per brick not used. Thus, the company will attempt to make as many impressive towers as possible, and then as many regular towers as possible.
This function receives as input parameter a number of bricks and it should return a string with the following information: first, the number of impressive towers to build, followed by two dots ("..") followed by the number of regular towers to build, followed again by two dots, followed by the number of unused bricks, followed by two dots and finally the money the company makes, considering the gains (becuase of the towers) minus the losses (becasue of the unused bricks).
bricksAndTowers(1027) should return '1..0..3..9940', because with 1027 bricks one impressive tower can be built (the first 1 in the string), no regular towers can be built (0) and there are 3 unused bricks. The company makes CDN$ 9940, that is, CDN$10000 because of the impressive tower minus CDN$ 60 (CDN$20 per each of the 3 unused bricks).
Notice that the company may have a net loss, when there are not enough bricks to build any tower.
bricksAndTowers(10) should return '0..0..10..-200'
if (bricks > 1024):
impressive_tower = 1
gain_loss = 10000
unused_bricks = bricks - 1024
elif (bricks == 1024):
unused_bricks = 0
elif (bricks < 1024):
impressive_tower = 0
unused_bricks = bricks
elif (bricks - 1024 > 256):
regular_tower = 1
elif (bricks - 1024 < 256):
regular_tower = 0
gain_loss = 10000 - unused_bricks * 20
result = impressive_tower + ".." + regular_tower + ".." + unused_bricks + ".." + gain_loss
imprTowers = int(bricks / 1024) # Impressive towers that can be built
bricks = bricks % 1024 # Remaining bricks
regTowers = int(bricks / 256) # Regular towers that can be built
bricks = bricks % 256 # Remaining bricks
cdn = (imprTowers * 10000) + (regTowers * 2000) - (bricks * 20) # Total CDN$
micseydel wrote:We are happy to help with homework, but you must make a reasonable effort before we do anything for you. Ask a question, don't just say what your prompt is. Post your best code attempt, even if it doesn't work. Post the traceback associated with your code, if it has one, and not just the error message.
Note to regulars: I've locked the original post, no need to quote it.
'Ichabod is ' + str(42) + ' years old.'
Users browsing this forum: GSD4ME, Yahoo [Bot] and 4 guests