Python Forum

Full Version: What role does module "sys" play in this code?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Below is code that was part of an exercise I found online. I completed the exercise in a different way, but their solution involves importing the "sys" module. However, I don't see any unfamiliar methods or object types in their code, so I don't understand why it was necessary to import this module:


Question 17
Level 2

Question:
Write a program that computes the net amount of a bank account based a transaction log from console input. The transaction log format is shown as following:
D 100
W 200
¡­
D means deposit while W means withdrawal.
Suppose the following input is supplied to the program:
D 300
D 300
W 200
D 100
Then, the output should be:
500

Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.

Solution:
import sys
netAmount = 0
while True:
    s = raw_input()
    if not s:
        break
    values = s.split(" ")
    operation = values[0]
    amount = int(values[1])
    if operation=="D":
        netAmount+=amount
    elif operation=="W":
        netAmount-=amount
    else:
        pass
    print netAmount
There is no need to import sys in this code. Maybe there is more to it?
That's all the code that there is. You can see that the print statement is at the bottom which is the end of the code.
There is no role.  It's imported, but never used.  Just extra words on the screen, man.
Sarcasm?