ment_eval.py, write the function interpret_statements(filename) that reads and interprets from the file filename a sequence of statements, one statement per line, ignoring lines that either have only space characters and/or a comment. The format of statements is described below. For each statement, your function should print the result of the evaluation. The format of the result is also described below.
If a line contains only space characters and/or a comment, the line should be ignored and no result displayed for it.
A comment starts with the hashtag symbol #. Everything on a line starting with the first hashtag should be ignored.
You should maintain a count of line numbers (the first line is line 1). Lines that are blank or that contain only comments are still counted for purposes of counting line numbers.
A statement can either be an expression statement or an assignment statement.
The format of these is:
An expression statement consists of a single expression. An expression is a sequence of operands separated by operators. One or more spaces separate the operands and operators. An operand is either a variable (that must have been previously defined in an assignment statement) or a number (an integer or floating point literal). An operator is either + or -. Examples of expression statements are:
23.4 + -19 + 98223
10 – 34 + 12.66 – 28 – 3323.2 + 12
92 – 13 # here is a comment after an expression
34 + 13#and another comment
14.4 – salary
time + salary – 10 + x123
The value of an expression is just what you would expect. Since the only operators allowed are + and -, the expression is evaluated left to right. You will need to store the value of variables somewhere, and a dictionary is good for this.The result printed for an expression statement should be the line number followed by the expression followed by a equal sign followed by the value of the expression. So, the results displayed by the above examples should be:
Line 1: 14.4 = 14.40
Line 2: 23.4 + -19 + 98223 = 98227.40
Line 3: 10 – 34 + 12.66 – 28 – 3323.2 + 12 = -3350.54
Line 4: 14.3 = 14.30
Line 5: 92 – 13 = 79.00
Line 6: 34 + 13 = 47.00
Line 7: x123 = 19278.00
Line 8: 14.4 – salary = -845.60
Line 9: time + salary – 10 + x123 = 1363.67
The last three results depend on the values of the variables, which are assigned in assignment statements. (And the description of assignment statement follows.)
An assignment statement consists of a variable name followed by an equal sign followed by an expression. (Expressions are described above.)A variable must start with a letter or underscore and be followed by any number of letters, digits, or underscores.Examples of valid assignment statements are:
x123 = 19278
salary = 873 – 13
time = -123.33 + salary – 123 + 23 + 0 + -123 – x123
x123 = x123 + 15 # reassign the value of x123
The result printed for an assignment statement should be the line number followed by the name of the variable being assigned to followed by an equal sign followed by the value assigned to the variable. The “side effect” of evaluating an assignment statement is to store the value of the variable in a dictionary, so that its value can be used in future expression and assignment statements.The results displayed by the above examples should be:
Line 1: x123 = 19278.00
Line 2: salary = 860.00
Line 3: time = -18764.33
Line 4: x123 = 19293.00
Any statement that is not a valid statement is an invalid statement. The result displayed for an invalid statement should be “Invalid statement”. Examples of invalid statements are:
820.34 – junk # junk has not been defined
2884 – -1293 + 399 t 266
23.8 – 203.3 +
Once you are convinced that your program runs correctly on all of the test inputs, you should verify this by running the program test_psa1.py. Do this by opening test_psa1.py, and then selecting from the VS Code menu View->Command Palette->“Python: Run Python File in Terminal”. The test program will tell you if your results are correct. (And if not, it will tell you the results that you got wrong.)
You should not submit your program until test_psa1.py tells you that you can submit. Your program will receive no points if your program fails this.
Program design requirements
Here are requirements related to the design of your program. Failure to follow these will not result in rejection of your program, but there will be deductions (as detailed under each item).
Your interpret_statements function should follow the design that we developed in class (the first two classes of the semester). You will still need to translate the algorithm we wrote into Python code, and add exception handling. You will also have to development an algorithm for the evaluate_expression function, and translate it into code, being sure to include exception handling.Neither of your functions should be longer than 30 lines of code, not counting blank lines or comments.Failure to use good procedural abstraction as we talked about in class will result in a penalty of 10 points.
Your program should define a BadStatement exception, and raise this exception any time an invalid statement is encountered. Failure to do this results in a 5 point penalty.
If your program cannot open the statements file, it should catch the resulting exception and print a meaningful message. Failure to do this results in a 5 point penalty.
To decide if a variable name is valid (starts with a letter or underscore, remaining characters either digits, letters, or underscores), you must use Python’s regular expression capability. Read about this at the Python documentation website, https://docs.python.org/3/howto/regex.html. (Regular expressions are a very powerful programming tool, and you will be happy to have been exposed to them.) Failure to do this results in a penalty of 5 points.
You should use descriptive variable names in your program, and use all lowercase letters with underscores separating words. Failure to do this results in a penalty of up to 5 points.
You should appropriately comment your program. It should have a header (this is started for you – be sure to add your names and the date you started it); each function should have a header. I’ve given you the header for the interpret_statements function. Any additional functions you add should have a descriptive header also.You should also comment blocks of code within your functions, explaining what the code is doing. How much commenting to add is a judgement call – you don’t want too much, or too little. If you have a block of code (say up to 10 lines long), put a brief comment before it saying what is about to happen. Then put blank lines between the blocks of code. Don’t comment individual lines of code, unless they are doing something that the reader might not see right away.Failure to comment your program appropriately will result in a penalty of up to 10 points.
Compelling correspondence is essential to the achievement all things considered but since of the changing idea of the present working environments, successful correspondence turns out to be more troublesome, and because of the numerous impediments that will permit beneficiaries to acknowledge the plan of the sender It is restricted. Misguided judgments.In spite of the fact that correspondence inside the association is rarely completely open, numerous straightforward arrangements can be executed to advance the effect of these hindrances.
Concerning specific contextual analysis, two significant correspondence standards, correspondence channel determination and commotion are self-evident. This course presents the standards of correspondence, the act of general correspondence, and different speculations to all the more likely comprehend the correspondence exchanges experienced in regular daily existence. The standards and practices that you learn in this course give the premise to additionally learning and correspondence.
This course starts with an outline of the correspondence cycle, the method of reasoning and hypothesis. In resulting modules of the course, we will look at explicit use of relational connections in close to home and expert life. These incorporate relational correspondence, bunch correspondence and dynamic, authoritative correspondence in the work environment or relational correspondence. Rule of Business Communication In request to make correspondence viable, it is important to follow a few rules and standards. Seven of them are fundamental and applicable, and these are clear, finished, brief, obliging, right, thought to be, concrete. These standards are frequently called 7C for business correspondence. The subtleties of these correspondence standards are examined underneath: Politeness Principle: When conveying, we should build up a cordial relationship with every individual who sends data to us.
To be inviting and polite is indistinguishable, and politeness requires an insightful and amicable activity against others. Axioms are notable that gracious “pay of graciousness is the main thing to win everything”. Correspondence staff ought to consistently remember this. The accompanying standards may assist with improving courtesy:Preliminary considering correspondence with family All glad families have the mystery of progress. This achievement originates from a strong establishment of closeness and closeness. Indeed, through private correspondence these cozy family connections become all the more intently. Correspondence is the foundation of different affiliations, building solid partners of obedient devotion, improving family way of life, and assisting with accomplishing satisfaction (Gosche, p. 1). In any case, so as to keep up an amicable relationship, a few families experienced tumultuous encounters. Correspondence in the family is an intricate and alluring marvel. Correspondence between families isn’t restricted to single messages between families or verbal correspondence.
It is a unique cycle that oversees force, closeness and limits, cohesiveness and flexibility of route frameworks, and makes pictures, topics, stories, ceremonies, rules, jobs, making implications, making a feeling of family life An intelligent cycle that makes a model. This model has passed ages. Notwithstanding the view as a family and family automatic framework, one of the greatest exploration establishments in between family correspondence centers around a family correspondence model. Family correspondence model (FCP) hypothesis clarifies why families impart in their own specific manner dependent on one another ‘s psychological direction. Early FCP research established in media research is keen on how families handle broad communications data. Family correspondence was perceived as an exceptional scholastic exploration field by the National Communications Association in 1989. Family correspondence researchers were at first impacted by family research, social brain science, and relational hypothesis, before long built up the hypothesis and began research in a family framework zeroed in on a significant job. Until 2001, the primary issue of the Family Communication Research Journal, Family Communication Magazine, was given. Family correspondence is more than the field of correspondence analysts in the family. Examination on family correspondence is normally done by individuals in brain science, humanism, and family research, to give some examples models. However, as the popular family correspondence researcher Leslie Baxter stated, it is the focal point of this intelligent semantic creation measure making the grant of family correspondence special. In the field of in-home correspondence, correspondence is normally not founded on autonomous messages from one sender to one beneficiary, yet dependent on the dynamic interdependency of data shared among families It is conceptualized. The focal point of this methodology is on the shared trait of semantic development inside family frameworks. As such, producing doesn’t happen in vacuum, however it happens in a wide scope of ages and social exchange.
Standards are rules end up being followed when performing work to agree to a given objective. Hierarchical achievement relies significantly upon compelling correspondence. So as to successfully impart, it is important to follow a few standards and rules. Coming up next are rules to guarantee powerful correspondence: clearness: lucidity of data is a significant guideline of correspondence. For beneficiaries to know the message plainly, the messages ought to be sorted out in a basic language. To guarantee that beneficiaries can without much of a stretch comprehend the importance of the message, the sender needs to impart unmistakably and unhesitatingly so the beneficiary can plainly and unquestionably comprehend the data.>