Upcoming SlideShare
×

# Questions3

389 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
389
On SlideShare
0
From Embeds
0
Number of Embeds
28
Actions
Shares
0
2
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Questions3

1. 1. WEEK THREE Problems for Week 3 Here are the problems for week 3 of the Challenge! Congratulations for getting this far. The more Python you learn the more interesting the problems become :) Remember, our scoring system is simple: each question with a submit link is worth 10 points. If you submit a solution that passes all of our tests the ﬁrst time you submit, you’ll get the full 10 points, but you’ll lose a point for every 5 incorrect submissions. 1 How Many Black Balloons? A recent report published by the Department of Climate Change states that in 2008, the Australian energy sector was responsible for the emission of greenhouse gases equivalent to 416 million tonnes of carbon dioxide. That’s more than from industrial processes, waste and agriculture combined! To encourage people to use less energy (and cut down on greenhouse gas emissions) the Victorian government has been running an ad campaign featuring black balloons. In the ads, the balloons ooze out of household appliances like kettles and dishwashers, and each balloon represents 50 grams of carbon dioxide. If the average household is reponsible for 12 tonnes of greenhouse gas each year, that’s 240 000 balloons per year. (We use the conversion factor of 50g of greenhouse gas per ballon). 12 tonnes = 12000 kg = 12000 kg / 0.050 kg per balloon = 240000 balloons Home electricity usage is usually measured in kiloWatt hours (kWh). Write a program to take electricity used in kiloWatt hours and convert it into an amount of greenhouse gas measured in black balloons. For example, the sticker on my fridge claims that under average running conditions it will consume 402 kiloWatt hours of electricity per year. Using the conversion factor of 0.89 kg of greenhouse gas per kWh from the Department of Climate Change workbook we can estimate that my fridge is responsible for 7156 balloons of greenhouse gas (rounded to the nearest whole balloon). 402 kWh * (0.89 kg per kWh) = 357.78 kg = 357.78 kg / (0.050 kg per balloon) = 7156 balloons (rounded to the nearest whole balloon) Your program will be given a single ﬂoating point number as input and should output that number converted into balloons, rounded to the nearest integer. For example, given the input: Electricity in kWh? 200.0 Your program should print out: 3560 balloons c National Computer Science School 2005-2009 1
2. 2. NCSS Challenge (Beginners) WEEK THREE Note, if the answer is one balloon, then it should print 1 balloon not 1 balloons. Hint You will probably want to use the built-in function round. 2 Think Outside the Square Raster graphics, for example bitmaps like GIF or JPEG images, look pixelated when you zoom in too close. Vector graphics, such as the Scalable Vector Graphics format, solves this problem by representing the image in terms of shapes that can be scaled, rotated and distorted mathematically. This means you can zoom in as far as you like, and each time the shapes are computed and then rendered onto the pixels of the screen or printer. You’re going to solve a simpliﬁed version of the rendering process — drawing a square of different sizes with dotted lines using asterisk (the * character) and space characters for pixels. Your program must ask the user for the length of the square in asterisks: Enter the length of the side? 4 and then print a square like this: * * * * * * * * * * * * The top line of output consists of an asterisk followed by a space, then an asterisk and so on, until you end up with the number of asterisk equal to the length of the side. The bottom line of output is the same. The middle lines only have an asterisk on either side and none in the middle. There should be no spaces after the last asterisk. To make your life a bit easier (but not too much!), we’re giving you some code to print out a ﬁlled in square of size 4. for i in xrange(4): print "* " * 3 + "*" The smallest square you will be asked to draw has a length of 2, and will therefore have zero stars missing in the middle: Enter the length of the side? 2 * * * * 3 X X marks marks the the spot spot Shiver me timbers! Pirate Bob still hasn’t managed to shake his pesky speech problems. However, he’s discovered that he can write perfectly ﬁne. He wants to give written instructions to the buried treasure for his shipmates, but needs to ﬁnd a way of making them secret in case they fall into the wrong hands. Bob is more of a ruthless pirate than a clever cryptographer, so the secret system he came up with is pretty easy to crack. All Bob does is hide his instructions as words that appear more than once in longer messages. So, for the message: right left forward left right words right and left are repeated, so the decrypted instructions are: left right c National Computer Science School 2005-2009 2