Difference between revisions of "CSC111 Homework 2 2015"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <bluebox> The due date for this homework is Tuesday 2/10 at 11:55 p.m. </bluebox> <br /> =Problem 1= <br /> Write a program called '''hw2_1.py''' that displays a ...")
 
(Problem 1)
Line 10: Line 10:
 
Write a program called '''hw2_1.py''' that displays a table of temperatures, the left column in Fahrenheit, and the right column in Celsius.  The program asks the user for two numbers, a temperature '''T''', and a number of temperatures '''n''', and displays a conversion table showing '''n''' lines of temperature conversions.
 
Write a program called '''hw2_1.py''' that displays a table of temperatures, the left column in Fahrenheit, and the right column in Celsius.  The program asks the user for two numbers, a temperature '''T''', and a number of temperatures '''n''', and displays a conversion table showing '''n''' lines of temperature conversions.
  
Here is an example of how your program should work:
+
Here is an example of how your program should work (the user input is in boldface):
  
  Please enter the starting temperature:  30
+
  Please enter the starting temperature:  '''30'''
  How many lines do you want for the table?  10
+
  How many lines do you want for the table?  '''10'''
 
    
 
    
 
  30        -1.11111111111
 
  30        -1.11111111111
Line 28: Line 28:
 
And here is another example:
 
And here is another example:
  
  Please enter the starting temperature:  32
+
  Please enter the starting temperature:  '''32'''
  How many lines do you want for the table?  4
+
  How many lines do you want for the table?  '''4'''
 
    
 
    
 
  32        0.0
 
  32        0.0
Line 37: Line 37:
  
 
* Submit your program on Moodle, in the HW2 PB1 section.
 
* Submit your program on Moodle, in the HW2 PB1 section.
 +
<br />
 +
=Problem 2=
 +
<br />
 +
Write a program called '''hw2_2.py''' that displays a table of temperatures, the left column in Fahrenheit, and the right column in Celsius.  The program asks the user for three numbers, a temperature '''T''', and a number of temperatures '''n''', and the '''step''' used to skip temperatures.  If the user enters 1 for the step, the output of this program will be the same as the output of the solution program for Problem 1.
 +
 +
Here is an example of how your program should work (the user input is in boldface):
 +
 +
Please enter the starting temperature:  '''30'''
 +
How many lines do you want for the table?  '''5'''
 +
What step should be used? '''2'''
 +
 +
30        -1.11111111111
 +
32        0.0
 +
34        1.11111111111
 +
36        2.22222222222
 +
38        3.33333333333
 +
 +
And here is another example:
 +
 +
Please enter the starting temperature:  '''38'''
 +
How many lines do you want for the table?  '''4'''
 +
What step should be used? '''-1'''
 +
 
 +
38        3.33333333333
 +
37        2.77777777778
 +
36        2.22222222222
 +
35        1.66666666667
 +
 +
 +
* Submit your program on Moodle, in the HW2 PB2 section.
 +
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
[[Category:CSC111]][[Category:Homework]][[Category:Python]]

Revision as of 20:44, 3 February 2015

--D. Thiebaut (talk) 20:38, 3 February 2015 (EST)


The due date for this homework is Tuesday 2/10 at 11:55 p.m.


Problem 1


Write a program called hw2_1.py that displays a table of temperatures, the left column in Fahrenheit, and the right column in Celsius. The program asks the user for two numbers, a temperature T, and a number of temperatures n, and displays a conversion table showing n lines of temperature conversions.

Here is an example of how your program should work (the user input is in boldface):

Please enter the starting temperature:  30
How many lines do you want for the table?  10
 
30         -1.11111111111
31         -0.555555555556
32         0.0
33         0.555555555556
34         1.11111111111
35         1.66666666667
36         2.22222222222
37         2.77777777778
38         3.33333333333
39         3.88888888889

And here is another example:

Please enter the starting temperature:  32
How many lines do you want for the table?  4
 
32         0.0
33         0.555555555556
34         1.11111111111
35         1.66666666667
  • Submit your program on Moodle, in the HW2 PB1 section.


Problem 2


Write a program called hw2_2.py that displays a table of temperatures, the left column in Fahrenheit, and the right column in Celsius. The program asks the user for three numbers, a temperature T, and a number of temperatures n, and the step used to skip temperatures. If the user enters 1 for the step, the output of this program will be the same as the output of the solution program for Problem 1.

Here is an example of how your program should work (the user input is in boldface):

Please enter the starting temperature:  30
How many lines do you want for the table?  5
What step should be used? 2 

30         -1.11111111111
32         0.0
34         1.11111111111
36         2.22222222222
38         3.33333333333

And here is another example:

Please enter the starting temperature:  38
How many lines do you want for the table?  4
What step should be used? -1 
 
38         3.33333333333
37         2.77777777778
36         2.22222222222
35         1.66666666667


  • Submit your program on Moodle, in the HW2 PB2 section.