**PYTHON*** I need a program written that can do the following: use the list of tuples given as a starting point for data. option 1 should print the full list of tuples, and the printing needs to be formatted so that the data lines up neatly. option 2 needs to work so that a user can enter the name, destination, and mileage for a new trip, and have that data be added as a tuple to the list. options 3 need to allow filtering the list by name option 4 just needs to allow the program to end if the user does not enter 1, 2, 3 or 4 as an option, you need to print an error message and have them re-enter their choice. there needs to be a main function that kicks things off, and you need to write a function to print the whole list, a function that allows inputting a new trip, and a function that filters by name and prints all the trips for that given name. These functions are called when the user types in a given option from the menu. if you add a new trip, everything should still work The menu options must be: Program Options. Display all trips Input new trip Display trips by Name Exit Each of the first 3 options should call a function to accomplish the proper task.   Tuples:   trips = [                (“alice”, ‘chicago’, 302),                (“bruce”, ‘chicago’, 309),                (“david”, ‘chicago’, 307),                (“carol”, ‘columbus’, 212),                (“alice”, ‘chicago’, 304),                (“bruce”, ‘chicago’, 301),                (“david”, ‘columbus’, 215),                (“alice”, ‘chicago’, 302),                (“carol”, ‘chicago’, 305),                (“bruce”, ‘chicago’, 304),                (“carol”, ‘columbus’, 218),                (“alice”, ‘columbus’, 217),                (“carol”, ‘chicago’, 309)                (“david”, columbus, 219)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

***PYTHON*** I need a program written that can do the following:

  1. use the list of tuples given as a starting point for data.
  2. option 1 should print the full list of tuples, and the printing needs to be

    formatted so that the data lines up neatly.

  3. option 2 needs to work so that a user can enter the name, destination,

    and mileage for a new trip, and have that data be added as a tuple to the

    list.

  4. options 3 need to allow filtering the list by name

  5. option 4 just needs to allow the program to end
  6. if the user does not enter 1, 2, 3 or 4 as an option, you need to print an

    error message and have them re-enter their choice.

  7. there needs to be a main function that kicks things off, and you need to

    write a function to print the whole list, a function that allows inputting a

    new trip, and a function that filters by name and prints all the trips for

    that given name. These functions are called when the user types in a

    given option from the menu.

  8. if you add a new trip, everything should still work

The menu options must be:

Program Options.

  • Display all trips
  • Input new trip
  • Display trips by Name
  • Exit

Each of the first 3 options should call a function to accomplish the proper task.

 

Tuples:

 

trips = [

               (“alice”, ‘chicago’, 302),

               (“bruce”, ‘chicago’, 309),

               (“david”, ‘chicago’, 307),

               (“carol”, ‘columbus’, 212),

               (“alice”, ‘chicago’, 304),

               (“bruce”, ‘chicago’, 301),

               (“david”, ‘columbus’, 215),

               (“alice”, ‘chicago’, 302),

               (“carol”, ‘chicago’, 305),

               (“bruce”, ‘chicago’, 304),

               (“carol”, ‘columbus’, 218),

               (“alice”, ‘columbus’, 217),

               (“carol”, ‘chicago’, 309)

               (“david”, columbus, 219)

 

 

Expert Solution
Step 1: Algorithm:

Step-1: Start
Step-2: Define function display_trips(trips)
    Step-2.1: Start loop for name, destination, mileage in trips
        Step-2.1.1: Print Name, Destination and Mileage
Step-3: Define function input_new_trip(trips)
    Step-3.1: Declare variable name and take input from the user
    Step-3.2: Declare variable destination and take input from the user
    Step-3.3: Declare variable mileage and take input from the user
    Step-3.4: In trips append (name, destination, mileage)
    Step-3.5: Print "Trip added successfully!"
Step-4: Define function display_trips_by_name(trips)
    Step-4.1: Declare variable name_to_filter and take input from the user
    Step-4.2: Declare variable filtered_trips and assign [(name, destination, mileage) for name, destination, mileage in trips if name == name_to_filter]
    Step-4.3: If filtered_trips
        Step-4.3.1: Print "Trips for (name_to_filter)"
        Step-4.3.2: Call function display_trips and pass argument filtered_trips
    Step-4.4: Else print "No trips found for (name_to_filter)."
Step-5: Define main function 
    Step-5.1: Declare variable trips and assign [
        ("alice", 'chicago', 302),
        ("bruce", 'chicago', 309),
        ("david", 'chicago', 307),
        ("carol", 'columbus', 212),
        ("alice", 'chicago', 304),
        ("bruce", 'chicago', 301),
        ("david", 'columbus', 215),
        ("alice", 'chicago', 302),
        ("carol", 'chicago', 305),
        ("bruce", 'chicago', 304),
        ("carol", 'columbus', 218),
        ("alice", 'columbus', 217),
        ("carol", 'chicago', 309),
        ("david", 'columbus', 219)
    ]
    Step-5.2: Start loop while True
        Step-5.2.1: Print "Program Options:"
        Step-5.2.2: Print "1. Display all trips"
        Step-5.2.3: Print "2. Input new trip"
        Step-5.2.4: Print "3. Display trips by Name"
        Step-5.2.5: Print "4. Exit"
        Step-5.2.6: Declare variable choice and take input from the user
        Step-5.2.7: If choice is equal to 1 then call function display_trips and pass argument trips
        Step-5.2.8: Elif choice is equal to 2 then call function input_new_trip and pass argument trips
        Step-5.2.9: Elif choice is equal to 3 then call function display_trips_by_name and pass argument trips 
        Step-5.2.10: Elif choice is equal to 4 then print "Exiting the program." and break
        Step-5.2.11: Else print "Invalid choice. Please enter 1, 2, 3, or 4."
Step-6: if __name__ == "__main__":
    Step-6.1: Call function main()
Step-7: Stop

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Linked List Representation
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education