Python Forum
What role does module "sys" play in this code?
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What role does module "sys" play in this code?
#1
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


User has been warned for this post. Reason: Repeatedly not using BBcode
Reply
#2
There is no need to import sys in this code. Maybe there is more to it?
Reply
#3
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.
Reply
#4
There is no role.  It's imported, but never used.  Just extra words on the screen, man.
Reply
#5
Sarcasm?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to run code again in module ? rajamani 2 864 Nov-10-2022, 02:38 PM
Last Post: snippsat
  How can I send a .mp3 to play through my mic? ejected 20 19,820 Sep-01-2022, 02:38 AM
Last Post: victormayer
  Play the next music in a list Pymax 0 1,181 Jul-28-2021, 07:27 PM
Last Post: Pymax
  how do i play an mp3 from a list gr3yali3n 3 2,074 Dec-01-2020, 08:50 AM
Last Post: Axel_Erfurt
  How to play against the computer Help_me_Please 4 3,991 Aug-29-2019, 03:37 PM
Last Post: ThomasL
  Discord Bot - If Person Mentions Role badmuchachob 0 2,188 Jan-30-2019, 06:39 PM
Last Post: badmuchachob
  SoX Sound Exchange sample code to Rec & Play audio file Fran_3 3 6,502 Sep-11-2017, 09:13 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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