Computers and Technology
Computers and Technology, 06.09.2021 23:30, Zgt

Write a program, in a file named population. py , which does the following: Your program will read an input string from the keyboard. You will print a prompt ( "file: " ) and then read an input string. Remove all leading and trailing whitespace from the input string, and then open a file with that name. You will then read through that file, reading the lines one at a time, and performing a calculation on the data. You must use a for loop to read the lines of the file; you may either directly use the for loop on the file, or read the lines into a list, and use a for loop over that. Your program should ignore any blank lines within the input (including lines that have some whitespace; treat a line as blank if it contains only whitespace). Likewise, your program should ignore any line within the input where the first non-whitespace character is ’#’ (so that we can place comments in the input file). REMEMBER: open(filename) will open a file, and return a file object. You can call readlines() on the object to get the lines of the file as a list.
Input File Format
The input file is a text file where each line (except blank lines and comments, see above) consists of the name of a US state or territory, together with its estimated 2019 population. For example:
Oklahoma 3943079
Oregon 4190713
South Dakota 882235
Pennsylvania 12807060
Northern Mariana Islands 55194
To simplify your input processing, you may assume that, between the words of the placename, we will only use single spaces. However, note that there might be any type of whitespace - and any number of whitespace characters - between the placename and the population number.
The Calculation
Read each line of the input file. For each line (other than the blank or comment lines), print out the information on two lines, as follows:
State/Territory: Oklahoma
Population: 3943079

State/Territory: Oregon
Population: 4190713
and so on.
At the very end of the output, print a blank line, followed by a summary of the information:
# of States/Territories:
Total Population:

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:30, relic7391
Is a string of code written to hurt others by damaging or destroying
Answers: 1
image
Computers and Technology, 23.06.2019 03:30, bellsbella34
Ihave a singular monitor that is a tv for my computer. recently, i took apart my computer and put it back together. when i put in the hdmi cord and booted the computer to see if it worked, the computer turned on fine but the screen was blue with "hdmi no signal." i've tried everything that doesn't require buying spare parts, any answer is appreciated!
Answers: 1
image
Computers and Technology, 23.06.2019 06:10, erick7123
The head restraint should be adjusted so that it reaches a. the top of your ears b. the base of your skull c. the top of the head
Answers: 1
image
Computers and Technology, 23.06.2019 12:50, tommy4260
Which syntax error in programming is unlikely to be highlighted by a compiler or an interpreter? a variable name misspelling a missing space a comma in place of a period a missing closing quotation mark
Answers: 1
Do you know the correct answer?
Write a program, in a file named population. py , which does the following: Your program will read a...

Questions in other subjects:

Konu
English, 18.09.2020 14:01
Konu
Mathematics, 18.09.2020 14:01
Konu
English, 18.09.2020 14:01
Konu
Mathematics, 18.09.2020 14:01
Konu
Geography, 18.09.2020 14:01
Konu
Mathematics, 18.09.2020 14:01
Konu
Mathematics, 18.09.2020 14:01
Konu
Mathematics, 18.09.2020 14:01
Konu
Mathematics, 18.09.2020 14:01
Konu
Mathematics, 18.09.2020 14:01