Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please write this code in python I can not upload the tr_cities.txt file but can you write the code assuming there is a

Can you please write this code in python

image text in transcribed

image text in transcribed

I can not upload the tr_cities.txt file but can you write the code assuming there is a tr_cities.txt file.

In this homework assignment, you will work on text files. First download the tr_cities.txt file that we put on Blackboard 1. It contains a list of selected cities in Turkey. Each line contains the following values separated with white space characters: 1. The first value is the city name. 2. The second and third values are the latitude and the longitude of this city, respectively. 3. Each city, which was read as the first value, may be a major city (in Turkish, IL) or a minor city/town (in Turkish, ILE or KASABA) belonging to a major city. The fourth value indicates the name of the major city that this city belongs to. 4. The fifth value is the population of this city. Note that for some small towns, the population information is not available. These populations are indicated with 1. Now implement a program that reads a text file, creates a dictionary of major cities according to the explanations given below, and writes this dictionary into another text file. This program also displays the most eastern, most western, most northern, and most southern cities on the screen. Please read the following carefully before starting your implementation. - Take the input filename from the user. You may assume that a file with this name always exists, and its contents are always valid. Note that tr_cities.txt is just an example file. We may run your program on other files with a similar format, that is, we may use other files that contain different values in its lines. - Create a dictionary of major cities, for which the key is the major city name. There are two values for an item in the dictionary: 1. Number of major/minor cities that this major city has, and 2. Total population of this city, including the populations of all cities that belong to this city. Note that for some small towns, the population information is not available. These populations are indicated with 1. Thus, do not include such cities in calculating the total population. - Write this dictionary into another txt file. Also take the name of this output file from the user. This file should have three values in each of its lines: major city name, city number, and total population. These values should be separated with a space. The first five rows of this output file created for tr_cities.txt are given below. Of course, this output file will contain more lines. IstanbulAnkaraIzmir46Bursa27Antalya204057083683169551341515400057513562888632 Display the most eastern, most western, most northern, and most southern cities on the screen (check the example output given below). To find the most eastern and most western cities, use the longitude information. To find the most northern and most southern cities, use the latitude information. Below are an example run. The first five rows of the output file, called city_summary.txt, are given above. Of course, this output file will contain more lines. Note that we will run your program on other files with a similar format, that is, we may use other files that contain different values in its lines. In [1]: runfile('/Users/hw4/hw4.py', wdir='/Users/hw4') Enter an input filename: tr_cities.txt Most eastern city: Esendere Most western city: Gokceada Most northern city: Sinop Most southern city: Yayladagi Enter an output filename: city_summary.txt Cities are saved WHAT TO SUBMIT? This homework assignment asks you to submit only one file whose name must be your_student_id.py. Use your own student id to give a name to this file. This file should also contain a function called main ( ) and a call to this main function. Like the previous homework assignments, the correctness of your program will affect your grade. However, in addition to this, the following points are important to get full credit. - You MUST use meaningful names for the variables. - You MUST write explanatory and clearly understandable comments. - At the beginning of each file, you MUST write your name, your id, and your section as comments. After these, you MUST provide a very brief description about what the program does as additional comments. For this assignment, you are allowed to use the codes given in our lecture slides. However, you ARE NOT ALLOWED to use any code from other sources (including the codes given in textbooks, found on the Internet, belonging to your classmates, etc.). Do not forget that plagiarism and cheating will be heavily punished. Please do the homework yourself. ***IMPORTANT: You cannot use the csv module in your implementation. This homework will be graded by your TAs, Nafiseh Jabbari Tofighi (ntofighi21@ku.edu.tr), Osman Yasal and Sleyman Yldrm (suleymanyildirim22@ku.edu.tr). Thus, you may directly contact them for your homework-related questions. Before submitting your homework, please be sure that you carefully read all explanations given above and understood them very well

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 11th British National Conference On Databases Bncod 11 Keele Uk July 7 9 1993 Proceedings Lncs 696

Authors: Michael F. Worboys ,Anna F. Grundy

1993rd Edition

3540569219, 978-3540569213

More Books

Students also viewed these Databases questions

Question

What is American Polity and Governance ?

Answered: 1 week ago

Question

1. Does your voice project confidence? Authority?

Answered: 1 week ago