WEEK
THREE
Problems for Week 3
Here are the problems for week 3 of the Challenge!
Congratulations for getting this far. Th...
NCSS Challenge (Beginners) WEEK THREE
Note, if the answer is one balloon, then it should print 1 balloon not 1 balloons.
H...
NCSS Challenge (Beginners) WEEK THREE
As you can see, the repeated words don’t have to immediately follow each other in th...
NCSS Challenge (Beginners) WEEK THREE
your program should produce:
line 1
line 2
line 3
c National Computer Science School...
Upcoming SlideShare
Loading in …5
×

Questions3

389 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
389
On SlideShare
0
From Embeds
0
Number of Embeds
28
Actions
Shares
0
Downloads
2
Comments
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 first 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 floating 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 simplified 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 filled 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 fine. He wants to give written instructions to the buried treasure for his shipmates, but needs to find 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
  3. 3. NCSS Challenge (Beginners) WEEK THREE As you can see, the repeated words don’t have to immediately follow each other in the message. However, the decrypted words are in the order of the repeats in the encrypted message. So, since the repeat of left is first, left is printed first, and then right is printed because it is repeated second. forward isn’t repeated, so it doesn’t get printed. If Bob repeats a word more than once (say it appears three times), then the second and third time it appears in the encrypted message, it should be printed out. Lastly, Bob never learnt any capitalisation or punctuation, so everything will be in lowercase letters, and since he’s a man of few words, the input will only be one line long. Here’s a real example of Bob’s encrypted instructions: right then the treasure be right on that island right where we left it then when ye left me and here’s what your code should print out: right right then left 4 Yuor biran is an azamnig thnig Can you raed tihs stencence? Apparently, the human brain can read misspelt words fairly easily as long as two things are true — the misspelling is an anagram of the correct spelling, and the first and last letters of the word are still the same. Two words are anagrams of each other if they contain the same letters in them. So left is an anagram of felt and vice-versa. We’ve decided to call the special anagrams with the same first and last letters Super Anagrams. Your program needs to read in two words on a single line. If the pair of words are Super Anagrams of each other, print out Super Anagram!. If the pair of words is not a Super Anagram (so a human couldn’t read it), then print out Huh?. For one-letter words, the first letter is the last letter. So if the input was brain brian your output would be Super Anagram! 5 sort | uniq Unix systems, like Linux, have some simple yet powerful tools for manipulating text files. One of those tools is called sort. It reads all of its lines of input and sorts the results. Another tool is called uniq. It reads all of its lines of input, and only prints lines that are different from the previous line. That is, it removes duplicate lines that are next to each other from its input. Unix also allows commands like these to be piped together, which means that the output from one command becomes the input to the next one. Your task here is to write a program that does the same job as sort | uniq — sorting a file and removing all of the duplicates. (The | character is called a pipe.) That is, your program should read all of its lines of input up until a blank line, then print out the unique ones, in sorted order. For example, given this input: line 1 line 2 line 1 line 3 line 2 c National Computer Science School 2005-2009 3
  4. 4. NCSS Challenge (Beginners) WEEK THREE your program should produce: line 1 line 2 line 3 c National Computer Science School 2005-2009 4

×