Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

you are supposed to build a software application that shows daily insight based

ID: 3589384 • Letter: Y

Question

you are supposed to build a software application that shows daily insight based on user input. When executed, the application should begin by reading in the application data from the data.dat configuration data file using the get_list function provided in the utilities.py module. The format of the data file is described below and is provided:

B Assignments _ × D BWA2 spec p V Lil B vs Pos 4 ,' (28278 ur reac , Mail-cgo ne x (28278 unreac × e chegg Study I C Secure https://mymasonportal.gmu.edu/bbcswebdav/pid-7169275-dt-content-rid-94978843_1/courses/82984.201770/BWA2_spec.pdf Subscriptions data file is described below and is provided: Quote of the Day 2 Education is the ability.. -Education is what. *Fact of the Day 3 Fractals, an important. According to a recent With the growing. "Book of the Day 4 Harry Potter -Origin Astrophysics for People in a Hurry I love my white shoes END The menu options are shown in RED here. Each menu option ends with a number which shows how many data is there. For example, there are 2 quotes of the day, 3 facts of the day. The items to be randomly selected from each menu option are shown in BLACK. The end-of-data file marker is shown in BLUE. The application should use the get list function to read in the data from the file. This function returns a list that contains each line of data from the file as a string element in the list. You must then develop an algorithm that will be implemented using a combination of control structures and sequential data structure operations that 1) dynamically builds the menu that will be presented to the user and 2) builds list data structure that maintains the data that will be randomly displayed to the user as each option is selected. Notice that the different groups of data (L.e., menu options, data & end-of-file) have unique characteristics related to the first character of the data line. The quote options start with"* the data options starts with " and the end of file is marked with "END" Please carefully examine the data.dat file. The key is to devise a way to iterate through the list containing all lines of the file and, 1) extract those lines that must be formatted and added to the menu string that will be presented to the user, menu line starts wit and ends with a number. The number is used for how many elements you will be reading next to build that particular list. For example the length of your quote list will be 2·This number needs to be removed while displaying the menu as shown below. 2) builds three different lists that can be accessed during application operation to display a random selection to the user. The data starts with “.. For random selection you can use the random module.

Explanation / Answer

import random

def get_list():
    data_file = open("data.dat","r");
    list_of_strings = data_file.readlines()
    data_file.close()
    return list_of_strings

data = get_list()

while True:
    print("========Daily Insight===========")
    print("1) -Quote of the Day")
    print("2) -Fact of the Day")
    print("3) -Pet of the Day")
    print("4) -Exit")

    ch = int(input("Enter option ===> "))
    if ch == 4:
       break
    if ch == 1:
       count = 0
       for line in data:
           if "Quote" in line:
               list = line.split(' ')
               n = int(list[len(list)-1])
               m = random.randint(0,n+1)
               print(data[count + m])
           count = count + 1
    if ch == 2:
       count = 0
       for line in data:
           if "Fact" in line:
               list = line.split(' ')
               n = int(list[len(list)-1])
               m = random.randint(0,n+1)
               print(data[count + m])
           count = count + 1
    if ch == 3:
       count = 0
       for line in data:
           if "Pet" in line:
               list = line.split(' ')
               n = int(list[len(list)-1])
               m = random.randint(0,n+1)
               print(data[count + m])
           count = count + 1