## Can someone help me to solve this python question please?

This is the place for queries that don't fit in any of the other categories.

### Can someone help me to solve this python question please?

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).

For example,

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.

For example:

bricksAndTowers(10) should return '0..0..10..-200'
ltcy

Posts: 12
Joined: Sat Feb 16, 2013 1:32 am

### Re: Can someone help me to solve this python question please

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.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: Can someone help me to solve this python question please

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).

For example,

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.

For example:

bricksAndTowers(10) should return '0..0..10..-200'

I have tried these codes :

Code: Select all
`if (bricks > 1024):impressive_tower = 1gain_loss = 10000unused_bricks = bricks - 1024elif (bricks == 1024):unused_bricks = 0elif (bricks < 1024):impressive_tower = 0unused_bricks = brickselif (bricks - 1024 > 256):regular_tower = 1elif (bricks - 1024 < 256):regular_tower = 0gain_loss = 10000 - unused_bricks * 20result = impressive_tower + ".." + regular_tower + ".." + unused_bricks + ".." + gain_lossreturn result`

AND

Code: Select all
`imprTowers = int(bricks / 1024) # Impressive towers that can be builtbricks = bricks % 1024 # Remaining bricksregTowers = int(bricks / 256) # Regular towers that can be builtbricks = bricks % 256 # Remaining brickscdn = (imprTowers * 10000) + (regTowers * 2000) - (bricks * 20) # Total CDN\$return cdn`

either one doesn't work out...I'm using Code Write to write the program.
Last edited by ltcy on Sat Feb 16, 2013 9:17 am, edited 1 time in total.
ltcy

Posts: 12
Joined: Sat Feb 16, 2013 1:32 am

### Re: Can someone help me to solve this python question please

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.

ltcy

Posts: 12
Joined: Sat Feb 16, 2013 1:32 am

### Re: Can someone help me to solve this python question please

Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: Can someone help me to solve this python question please

Just for starters, your indentation is wrong and you are using return when not using a function or method.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

Yoriz

Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

### Re: Can someone help me to solve this python question please

Yeah, that second bit of code looks like it would work if you put it in a function definition. At least it would return the right profit or loss for the company. To get the string output requested by the problem, there's lots of options. The easiest is just string addition:

Code: Select all
`'Ichabod is ' + str(42) + ' years old.'`
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016.
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
ichabod801

Posts: 688
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC