Description: Description: Description: Description: Description: Description: Description: Description: Breaking News! Click here for details.

 CSC 131 - Introduction to Computer Science

Homework 4 Due Thursday, Sep. 14, 11:59pm

Submitted on Blackboard (learn.uncw.edu)

Three programs based on material from Chapter 4.3.2 and Chapter 8.

 

Program 1: Fahrenheit to Celsius

Using a for loop, print out the following table. This program does not use any input/output or file I/O. Remember the formula to convert Fahrenheit to Celsius: (F 32)*5/9.

F C

0 -18

10 -12

20 -7

30 -1

40 4

50 10

60 16

70 21

80 27

90 32

100 38

110 43

120 49

130 54

140 60

150 66

160 71

170 77

180 82

190 88

200 93

210 99

220 104

230 110

240 116

250 121

 

 

Program 2: Count Negative From a File

Write a Python program, CountNegative.py, which

1.      Asks the user for a name of a file containing a list of numbers, one per line.

2.      Reads in the file of numbers.

3.      Counts how many numbers are negative.

4.      Keeps track of how many total numbers there are.

5.      Prints out how many of the numbers were negative. Here is a sample output:

 

What is the name of the file? small.txt

There are 2 negative numbers out of 5 in the file small.txt.