Python Forum
programming assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
programming assignment
#1



You are going to write a program that reads data from a file into a list and allows the user to query and modify the data. You may assume that the file is formatted properly for this assignment.


Design specifications: The program must use lists. For full credit, the program should read all data from one file (see Appendix A). For slightly less credit (-5), the program could read all data from four files (one for names, one for continents, one for populations, and one for areas) (see Appendix B). For less credit than that (-10), the program can hard-code in the three lists of data (see Appendix C). (Start with hard-coded lists, get the program working, and then work on reading in the lists from files.) For each menu option, there should be a function that takes the lists as parameters. There should be no global variables.
Reply
#2
Sounds like fun.  Hope you get an A.
Reply
#3
Reading data from four files line by line sounds cool. This remind me to look into contextlib.
Example without modification of data:

import contextlib
import sys


def read_files_iterative(filenames):
    with contextlib.ExitStack() as stack:
        try:
            files = [stack.enter_context(open(fname)) for fname in filenames]
        except (FileNotFoundError, PermissionError) as e:
            print(e, file=sys.stderr)
            raise
        for data in zip(*files):
            yield data

def main():
    if len(sys.argv) != 5:
        print('4 Filenames are required')
        return 1
    filenames = sys.argv[1:5]
    try:
        for row in read_files_iterative(filenames):
            print(row)
    except:
        return 2
    # putting them into a list:
    # content = list(read_files_iterative(filenames))
    # print(content)
    return 0

if __name__ == '__main__':
    # be a nice shell citizen and return an error code
    sys.exit(main())
Conclusion: This code won't help you and it does not fit to your professors requirements.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Verilog HDL Programming to Python Programming? noobcoder 1 3,032 Jul-18-2019, 09:28 PM
Last Post: nilamo
  Help for my assignment - Object Oriented Programming denizkb 5 5,084 Jan-05-2019, 06:43 PM
Last Post: stullis
  Unit 18: Procedural Programming Assignment (Shop Simulation) shaheduk323 28 13,379 Dec-17-2017, 08:31 PM
Last Post: Terafy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020