Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Please follow the following Python code to complete this exercise:

 

"""
PROGRAMMING ASSIGNMENT 07
Filename: 'exercise1.py'
"""
# Place your imports here if any

def build_attraction_dict(filename):
    """
    Read from the file for which the filename was given and returns a dictionary

    The key / value pairs in the dictionary will be:
        • key → attraction name (str type)
        • value → Province (str type)
    """
    # TODO


def add_attraction(dic):
    """
    This function takes a dictionary as a parameter and does not return anything.

    The function:
        • asks the user to input an attraction name
        • asks the user to input a province
        • updates the dictionary with a new key / value pair (with a similar format for
        task 1)
    """
    # TODO


def build_province_attraction_dict(dic):
    """
    This function takes a dictionary as a parameter and returns another dictionary.

    The input dictionary is constituted of key / value pairs similar to the ones built in task 1.

    The returned dictionary should have key / value pair with:
        • key → Province (str type)
        • value → list of attraction names (list of str type) associated to the Province
    """
    # TODO


def most_attractions(dic):
    """
    This function takes a dictionary as a parameter and returns a set.

    The input dictionary is constituted of key / value pairs similar to the ones built in task 3.

    The returned set should contain the Provinces which have at least 3 tourist attractions
    (in the input dictionary).
    """
    # TODO


def main():
    """
    The main() function will
        1. calls `build_province_attraction_dict` with filename top_tourist_attractions.txt as 
            parameter to generate the first dictionary.
        2. calls `add_attraction` one time in order to update the dictionary. The user will input
            a new (non-existing) attraction name/Province pair.
        3. calls `build_province_attraction_dict` in order to generate a second dictionary.
        4. calls `most_attractions` in order to generate the set of Provinces with at least 3 attractions.
        5. prints the Provinces with at least 3 attractions. Display one Province per line.
            See sample examples for the proper format (empty line + Header line).
            
    """
    # TODO


if __name__ == '__main__':
    main()
Below is the top_tourist_attractions.txt:

Yunnan,Three Pagodas
Hunan,Zhangjiajie National Forest Park
Yunnan,Shilin Stone Forest
Yunnan,Lijiang Old Town
Hubei,Wudang Mountains
Jiangsu,Zhouzhuang
Shandong,Mount Tai
Yunnan,Tiger Leaping Gorge
Jiangsu,Suzhou Gardens & Canals
Shaanxi,Xi an City Walls
Gansu,Mogao Caves
Guangxi,Longji Terraces
Beijing,Summer Palace
Shanxi,Hanging Monastery
Guangxi,Reed Flute Cave
Shanxi,Yungang Grottoes
Zhejiang,West Lake
Sichuan,Jiuzhai Valley
Henan,Longmen Grottoes
Shanghai,Pudong Skyline
Yunnan,Hani Terraces
Sichuan,Leshan Giant Buddha
Anhui,Yellow Mountain
Guangxi,Li River Cruise
Shaanxi,Terracotta Army
Hongkong,Victoria Harbour
Beijing,Forbidden City
Xizang,Potala Palace

Exercise 1 - Top Tourist Attractions in China
The top_tourist_attractions.txt file (in the same folder as your program) contains some top
tourist attractions in China and their location (Province). Check the format in the file.
This exercise consists of 5 tasks (to be coded in exercise1.py):
Task 1
Write a function named build_attraction_dict which takes a filename ( str type) as
a parameter, and returns a dictionary.
The key / value pairs in the dictionary will be:
• key → attraction name ( str type)
value → Province ( str type)
read from the file for which the filename was given. The file is supposed to have a format
similar to top_tourist_attractions.txt.
Task 2
Write a function named add_attraction which takes a dictionary as a parameter and
does not return anything.
The function:
• asks the user to input an attraction name
• asks the user to input a province
updates the dictionary with a new key / value pair (with a similar format for task
1)
Task 3
Write a function named build province_attraction dict which takes a dictionary as
a parameter and returns another dictionary.
The input dictionary is constituted of key / value pairs similar to the ones built in task 1.
The returned dictionary should have key / value pairs with:
• key → Province ( str type)
value → list of attraction names
list of str type) associated to the Province
Task 4
Write a function named most_attractions which takes a dictionary as a parameter
and returns a set.
The input dictionary is constituted of key / value pairs similar to the ones built in task 3.
The returned set should contain the Provinces which have at least 3 tourist attractions
(in the input dictionary).
expand button
Transcribed Image Text:Exercise 1 - Top Tourist Attractions in China The top_tourist_attractions.txt file (in the same folder as your program) contains some top tourist attractions in China and their location (Province). Check the format in the file. This exercise consists of 5 tasks (to be coded in exercise1.py): Task 1 Write a function named build_attraction_dict which takes a filename ( str type) as a parameter, and returns a dictionary. The key / value pairs in the dictionary will be: • key → attraction name ( str type) value → Province ( str type) read from the file for which the filename was given. The file is supposed to have a format similar to top_tourist_attractions.txt. Task 2 Write a function named add_attraction which takes a dictionary as a parameter and does not return anything. The function: • asks the user to input an attraction name • asks the user to input a province updates the dictionary with a new key / value pair (with a similar format for task 1) Task 3 Write a function named build province_attraction dict which takes a dictionary as a parameter and returns another dictionary. The input dictionary is constituted of key / value pairs similar to the ones built in task 1. The returned dictionary should have key / value pairs with: • key → Province ( str type) value → list of attraction names list of str type) associated to the Province Task 4 Write a function named most_attractions which takes a dictionary as a parameter and returns a set. The input dictionary is constituted of key / value pairs similar to the ones built in task 3. The returned set should contain the Provinces which have at least 3 tourist attractions (in the input dictionary).
Task 5
Write the main() function that:
1. calls build_attraction_dict with filename top_tourist_attractions.txt as pa-
rameter to generate the first dictionary.
2. calls add_attraction one time in order to update the dictionary. The user will input
a new (non-existing) attraction name/Province pair.
3. calls build_province_attraction_dict in order to generate a second dictionary.
4. calls most_attractions in order to generate the set of Provinces with at least 3 at-
tractions.
5. prints the Provinces with at least 3 attractions. Display one Province per line. See
sample examples for the proper format (empty line + Header line).
Sample example 1 with the file top_tourist_attractions.txt (the user input is in red, the
printed output is in blue (also with the empty line)):
Input a new attraction: The Bund
Input the province: Shanghai
Provinces with at least 3 attractions:
Yunnan
Guangxi
Sample example 2 with the file top_tourist_attractions.txt (the user input is in red, the
printed output is in blue (also with the empty line)):
Input a new attraction: Tiananmen
Input the province: Beijing
Provinces with at least 3 attractions:
Yunnan
Guangxi
Beijing
expand button
Transcribed Image Text:Task 5 Write the main() function that: 1. calls build_attraction_dict with filename top_tourist_attractions.txt as pa- rameter to generate the first dictionary. 2. calls add_attraction one time in order to update the dictionary. The user will input a new (non-existing) attraction name/Province pair. 3. calls build_province_attraction_dict in order to generate a second dictionary. 4. calls most_attractions in order to generate the set of Provinces with at least 3 at- tractions. 5. prints the Provinces with at least 3 attractions. Display one Province per line. See sample examples for the proper format (empty line + Header line). Sample example 1 with the file top_tourist_attractions.txt (the user input is in red, the printed output is in blue (also with the empty line)): Input a new attraction: The Bund Input the province: Shanghai Provinces with at least 3 attractions: Yunnan Guangxi Sample example 2 with the file top_tourist_attractions.txt (the user input is in red, the printed output is in blue (also with the empty line)): Input a new attraction: Tiananmen Input the province: Beijing Provinces with at least 3 attractions: Yunnan Guangxi Beijing
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education