help with python code import time timeStamp = time.ctime() print(timeStamp) forum_list = [     {'date':'10-01-2022', 'name':'Student1', 'comment':'Very helpful'},     {'date': '10-01-2022', 'name': 'Student2', 'comment': 'Very good'}     ]

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

help with python code


import time

timeStamp = time.ctime()
print(timeStamp)
forum_list = [
    {'date':'10-01-2022', 'name':'Student1', 'comment':'Very helpful'},
    {'date': '10-01-2022', 'name': 'Student2', 'comment': 'Very good'}
    ]


menu = """

Forum Comments

0: Exit

1: Display Comments

2: Add Comment

"""

done = False

while not done:
    
    print(menu)
    
    selection = input('Please make a selection: ')

    if selection == "0":
        done = True
        print('Exiting now, thank you for participating')
        
    if selection == "1":
        for d in forum_list:
            print(d['date'], end='')
            print(' ', end='')
            print(d['name'])
            print(d['comment'])
        
    if selection == "2":
        comment = {}
        comment['date'] = input('Please enter date: ')
        comment['name'] = input('Please enter name: ')
        comment['comment'] = input('Please enter comment: ')
        forum_list.append(comment)

 

 

# what's inside the data.txt file 

#Date Name Comment
#Sun Jul 24 12:39:15 2022 joe dogs sniff alot!
#Sun Jul 24 12:39:43 2022 kate cats sleep a lot

 

2. Store the name of the text file in a variable.
3. Use a try/except/else block to open the file.
4. If a FileNotFoundError exception is thrown, display a message to the user indicating that the file could not be found
and quit the program with the quit() function. If this happens, it's either because the text file is not in the same folder as
your program file or there's a spelling error in the file name.
5. In the else block, which we only get to if we have successfully opened the file:
A. Read and discard the first line of the file using readline(). This is the column heading line and we don't need it.
B. In a for loop, read each line of the file and strip the trailing line break. Split the line using the split() method and a tab
as the delimiter, "\t".
C. The split should return three fields, which are the values for the timestamp, the name and the comment.
D. Create a dictionary with keys of "date", "name" and "timestamp" and use the values provided by the strip() call.
E. Append the dictionary to the records list.
6. Test your program.
A. First choose Menu Selection 1. You should see each record from the file displayed.
B. Choose Menu Selection 2 and add another entry.
C. Choose Menu Selection 1 again and you should see the original records, along with the one you have added.
7. Note that if you run the program again, none of the new records you entered via Menu Selection 2 will show because
we haven't updated the text file. That's part of the final step.
Transcribed Image Text:2. Store the name of the text file in a variable. 3. Use a try/except/else block to open the file. 4. If a FileNotFoundError exception is thrown, display a message to the user indicating that the file could not be found and quit the program with the quit() function. If this happens, it's either because the text file is not in the same folder as your program file or there's a spelling error in the file name. 5. In the else block, which we only get to if we have successfully opened the file: A. Read and discard the first line of the file using readline(). This is the column heading line and we don't need it. B. In a for loop, read each line of the file and strip the trailing line break. Split the line using the split() method and a tab as the delimiter, "\t". C. The split should return three fields, which are the values for the timestamp, the name and the comment. D. Create a dictionary with keys of "date", "name" and "timestamp" and use the values provided by the strip() call. E. Append the dictionary to the records list. 6. Test your program. A. First choose Menu Selection 1. You should see each record from the file displayed. B. Choose Menu Selection 2 and add another entry. C. Choose Menu Selection 1 again and you should see the original records, along with the one you have added. 7. Note that if you run the program again, none of the new records you entered via Menu Selection 2 will show because we haven't updated the text file. That's part of the final step.
Expert Solution
Step 1 Introduction

Python which refers to the high-level, general-purpose programming language. Its design which emphasizes the code readability with the use of significant indentation. Python which is also dynamically-typed and garbage-collected. It supports multiple programming paradigms, including structured, object-oriented and the  functional programming

steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY