Difference between revisions of "CSC111 Homework 4 2014"

From dftwiki3
Jump to: navigation, search
(The Output)
(Hints)
Line 101: Line 101:
 
* You do not need any new constructs.  All the Python constructs we have seen so far are sufficient to solve this problem.
 
* You do not need any new constructs.  All the Python constructs we have seen so far are sufficient to solve this problem.
 
* the word '''end''' will act as a sentinel
 
* the word '''end''' will act as a sentinel
* because you need to average the temperatures, you need to keep track of the sum and count for a given city.  You should first solve a simpler problem where you ask the user to enter a collection of numbers followed by a sentinel, and then output the average of all the numbers entered.  If you can solve this simpler problem, solving Problem 3 will be a short hop away!
+
* because you need to average the temperatures, you need to keep track of the sum and count of temperature values for each city.  '''You should first solve a simpler problem where you ask the user to enter a collection of numbers followed by a sentinel, and then output the average of all the numbers entered'''.  If you can solve this simpler problem, solving Problem 3 will be a short hop away!
 
* You do not need anything fancy to get the temperature from the string that will contain the city name and the temperature.  If you  can remove Boston from "Boston    31" you get "    31" and you should be able to easily transform this into the integer '''31'''.
 
* You do not need anything fancy to get the temperature from the string that will contain the city name and the temperature.  If you  can remove Boston from "Boston    31" you get "    31" and you should be able to easily transform this into the integer '''31'''.
  

Revision as of 16:54, 19 February 2014

--D. Thiebaut (talk) 12:26, 18 February 2014 (EST)



This assignment can be do individually or in Programming-Pair mode. You are not restricted in your selection of a partner if you are working in pair. The assignment is due on Thursday evening, February 27th, 2014, at midnight.






Problem #1


Rewrite the Rock-Scissors-Paper game using while loops. Call your program hw4a.py.

Requirements


  • The program will stop only once the difference in score between computer and human players is 3.
  • You should not include the mug of Homework 3 in this program/game.
  • The program will keep on prompting the user if the input is not one of 'P', 'R', or 'S'. The program will accept valid letters in lower or upper case, and with extra spaces before or after the letter.
  • The program will indicate the winner of each round.
  • The program will output a final string at the end, when the difference in score is 3, pointing out and congratulating the winner.



Problem #2: Magic Lily


Assume that we have a put a magic lily in Paradise Pond. The magic lily grows in surface every 24 hours. When we first put it in the pond, it is only 1 square inch in area. We approximate the size of the pond to be 31,416 square feet.

We assume that the lily is magic is that it can cover areas that are as irregular as the pond is. It's magic, remember?

Write a program that uses a while loop and that outputs the number of days it will take for the lily to cover the whole pond. Make your program output all the known information and the final result (the actual result shown here is incorrect, on purpose).


Magic Lily
Initial size: 1 square inch 
Growth rate: 2 times its size in 1 day
Pond size: 31416 square feet
Minimum number of days required to cover the whole pond (or more): 16 days

Call your program hw4b.py.

Additional Information

Computation


Those of you who are math inclined can probably figure out an equation giving the size of the lily after some number of days. You are welcome to code this equation to verify the output of your while loop, but you need to also compute the solution using a while loop that doubles the size of the lily every iteration.

Conversion


Use the Web to convert square feet into square inches. Wolfram Alpha is a great resource for every type of translation from one unit into another.

Where did Paradise Pond get its name?


Could it be the Swedish Nightingale Jenny Lind? You can read all about it here!

Approximating the Area of the Pond


I simply tried to cover a map of the pond with disks that had a diameter of 200 ft. Some disks overlap, some area of the pond is not covered, and I tried to make both the overlap and the non-covered area about the same. I counted 16 disks.

ParadisePondArea.png



Problem 3 (Optional and Extra Credits)


Write a program called hw4c.py that gets input from the keyboard and outputs some statistics about the input. TAs are allowed to help out with this assignment.

The Input


  • The input provided by the user will be lines containing the name of a city followed by a temperature. The name of the cities will be either Boston, New York, or Montreal. The city names will never be misspelled.
  • The temperature will be an integer number.
  • There will be at least one space between the city name and the temperature.
  • When the user does not have any more information to provide, she will enter the single word end on the last line. The program will use this word as a sentinel and will stop getting input from the user.


The Output


The program will output the average temperature (as a float or as an integer) in each of the 3 cities.

Here is an example of an interaction with the program. The user input is in boldface.

Please enter temperature recording for Boston, New York or Montreal.  Enter the word "end" to stop.
> Boston 20
> Boston           33
>        Boston       40
> New York 10
> end

Average temperature for Boston: 31
Average temperature for Montreal: None entered
Average temperature for New York: 10


Hints


  • You do not need any new constructs. All the Python constructs we have seen so far are sufficient to solve this problem.
  • the word end will act as a sentinel
  • because you need to average the temperatures, you need to keep track of the sum and count of temperature values for each city. You should first solve a simpler problem where you ask the user to enter a collection of numbers followed by a sentinel, and then output the average of all the numbers entered. If you can solve this simpler problem, solving Problem 3 will be a short hop away!
  • You do not need anything fancy to get the temperature from the string that will contain the city name and the temperature. If you can remove Boston from "Boston    31" you get "    31" and you should be able to easily transform this into the integer 31.

Submission


Submit your programs to cs.smith.edu/~thiebaut/111b/submit4.php.