1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
GrogVix [38]
3 years ago
15

"For your final challenge in this unit, you will load two files. The first file F1 will have information about some accounts. It

will be pipe-delimited and have one record per line, with these fields: ACCOUNT NUMBER | PIN CODE | BALANCE The second file F2 will contain instructions: one on each line. The instructions will look like this: COMMAND | AMOUNT | ACCOUNT NUMBER | PIN CODE COMMAND will be either add or sub. If the command is add, you will add AMOUNT to the BALANCE in the account files F1. If the command is sub, you will subtract."
Computers and Technology
1 answer:
nadya68 [22]3 years ago
3 0

Answer:

Python script explained below. Highlighted comment important for proper running of code

Explanation:

# Get the filepath from the command line

import sys, os

#if you get an error message via the above,

#Change the import sys at the top to

#import sys, os from collections import OrderedDict

from collections import OrderedDict

# The command-line arguments

F1 = sys.argv[1]

F2 = sys.argv[2]

# Your code goes here

#empty dictionary for holding pin_code data read from F1

balance_dict = OrderedDict()

#iterate through each line in F1 and store in the balance_dict with account_number number as the key

#handle the case in which the file doesn't or the path is wrong

try:

   #open F1 for reading

   with open(F1, 'r') as balance_file:

       for line in balance_file.readlines():

           #split the line by "|", and store data, strip any extra white spaces

           account_number, pin_code, balance = line.strip().split("|")

           #strip white spaces for each variables

           account_number = account_number.strip()

           pin_code = pin_code.strip()

           balance = int(balance .strip())

           #store the values into the dictionary

           balance_dict[account_number] = { "pin_code" : pin_code, "balance" : balance }

   #open F2 for reading

   with open(F2, 'r') as transaction_file:

       #go through each line of F2

       for line in transaction_file.readlines():

           #extract data

           command, amount, account_number, pin_code = line.strip().split("|")

           #strip each variable string of extra white spaces, and convert into proper types as well

           command = command.strip()

           amount = int(amount.strip())

           account_number = account_number.strip()

           pin_code = pin_code.strip()

           #handle the case in which the key doesn't exist in the dict

           try:

               #check the given pin_code matches or not

               if pin_code == balance_dict[account_number]["pin_code"]:

                   #check what the command is

                   if command.lower() == "add":

                       #add amount to balance

                       balance_dict[account_number]["balance"] += amount

                   elif command.lower() == "sub":

                       #compute balance

                       new_balance = balance_dict[account_number]["balance"] - amount

                       #check if balance is negative or not

                       if new_balance >= 0:

                           #if not, update

                           balance_dict[account_number]["balance"] -= amount

           except KeyError:

               print("Oops!! Account number doesn't exist in F1")

   #open F1 for writing updated balances

   with open(F1, 'w') as balance_file:

       #go through each item in balance_dict

       for key in balance_dict:

           #construct the line to write to F1

           line = key + "|" + balance_dict[key]["pin_code"] + "|" + str(balance_dict[key]["balance"]) + os.linesep

           balance_file.write(line)

except IOError:

   print("Either a file doesn't exist or a path is wrong!!")

You might be interested in
An identifier that is prefixed with an @ and allows you to use code written in other languages that do not have the same set of
Nina [5.8K]

Answer:

Verbatim Identifier

Explanation:

  • Verbatim Identifier contains @ symbol as a prefix by which enables you to use reserved words of a programming language as identifier. For example the keywords like int, double, goto, char, else, while, for, float etc can be used as strings or variable names if @ symbol is added before these words e.g. @char, @while, @void, @int etc.
  • The compiler of a language will recognize such identifiers as verbatim identifiers and compiles them without giving an error that these are reserved words.
  • Verbatim identifier is used for program that is written in other languages and those languages don't have same reserved words.
  • For example: cout<<"use of verbatim identifier";<<@for;   In this statement, for keyword which is used in for loop can be used as an identifier with @ in the prefix.
  • The escape sequences if used with @ symbol in prefix then they are interpreted in a different way. For example in C#

                              string a = "\\C:\torrent\new\file";

                              Console.WriteLine(a);

This statement will give the following output:

                              \C:          orrent

                               ewfile

This means that the \t in the start of torrent and \n in the start of new word is taken as an escape sequence and output displayed is giving tab space because of \t and prints the rest of the words in new line because of \n escape sequence.

Now lets use this with the @ symbol

                               string a = @"\\C:\torrent\new\file";

                                Console.WriteLine(a);

The output will now be:

                                \\C:\torrent\new\file

\t and \n are not taken as escape sequences by the compiler because of @ symbol.

4 0
4 years ago
The measure of the maximum amount of data that can travel through a computer’s communications path in a given amount of time is
STatiana [176]

Answer:

Bandwidth

Explanation:

Bandwidth is the rate of transfer of data in the given time. Its unit is Bit/sec.

It is used to measure the transfer rate of bit in a network.

4 0
4 years ago
What is one way to improve the upward flow of information?
kobusy [5.1K]

Answer:

b.Encourage managers to have regular meetings with staff.

Explanation:

Upward flow of information is when the information is flown from the lower level of hierarchy to upper level of hierarchy in an organization. for example:- the flow of information from employees to the managers.

The upward flow of information can be improved by encouraging the managers to have meeting with the staff at regular interval of time.

4 0
4 years ago
The amount of money you can charge to a credit card is called
Novosadov [1.4K]
Transfer fee or just fee.
8 0
3 years ago
Now that the classList Array has been implemented, we need to create methods to access the list items.
natima [27]

The following code will be applied to Create the following static methods for the Student class

<u>Explanation:</u>

/* Note: Array index starts from 0 in java so ,, user ask for 1 index then the position will be i-1 , below program is based on this concept if you dont want this way just remove -1 from classList.get(i-1).getName(); ,and classList.add(i-1,student); */

/* ClassListTester.java */

public class ClassListTester

{

public static void main(String[] args)

{

//You don't need to change anything here, but feel free to add more Students!

Student alan = new Student("Alan", 11);

Student kevin = new Student("Kevin", 10);

Student annie = new Student("Annie", 12);

System.out.println(Student.printClassList());

System.out.println(Student.getLastStudent());

System.out.println(Student.getStudent(1));

Student.addStudent(2, new Student("Trevor", 12));

System.out.println(Student.printClassList());

System.out.println(Student.getClassSize());

}

}

/* Student.java */

import java.util.ArrayList;

public class Student

{

private String name;

private int grade;

//Implement classList here:

private static ArrayList<Student> classList = new ArrayList<Student>();

public Student(String name, int grade)

{

this.name = name;

this.grade = grade;

classList.add(this);

}

public String getName()

{

return this.name;

}

//Add the static methods here:

public static String printClassList()

{

String names = "";

for(Student name: classList)

{

names+= name.getName() + "\n";

}

return "Student Class List:\n" + names;

}  

public static String getLastStudent() {

// index run from 0 so last student will be size -1

return classList.get(classList.size()-1).getName();

}

public static String getStudent(int i) {

// array starts from 0 so i-1 will be the student

return classList.get(i-1).getName();

}

public static void addStudent(int i, Student student) {

// array starts from 0 so, we add at i-1 position

classList.add(i-1,student);

// remove extra student

classList.remove(classList.size()-1);

}  

public static int getClassSize() {

return classList.size();

}

}

7 0
4 years ago
Other questions:
  • A(n) ____________ is a program that translates a high-level language program into a separate machine language program.
    7·1 answer
  • A bookmarking site is a website that enables members to manage and share media such as photos, videos, and music. true or false
    14·1 answer
  • Some files appear dimmed in one of the default folders on your computer. What would be the best course of action? A. Leave the f
    5·1 answer
  • True or False <br><br> The term virus and malware may be used interchangeably.
    13·1 answer
  • Your company runs several databases on a single MySQL instance. They need to take backups of a specific database at regular inte
    12·1 answer
  • A(n) _____ is money paid for work.<br><br> A. raise <br> B. allowance<br> C. wage<br> D. grant
    14·2 answers
  • Which HTML tag is used to add a paragraph to a web page?
    15·1 answer
  • I need help with workplace safety systems please help
    10·1 answer
  • Which of the following candidates would most likely be hired as a graphic artist?
    15·2 answers
  • Which wireless standard runs on both the 2.4 and 5 GHz frequencies?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!