Guest User

Untitled

a guest
Jan 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. # Question 17
  2. ### Level 2
  3. --------------------
  4.  
  5. **Question:**
  6.  
  7. ***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:***
  8.  
  9. ***D 100***
  10.  
  11. ***W 200***
  12.  
  13. ***¡­***
  14.  
  15. ***D means deposit while W means withdrawal.***
  16.  
  17. ***Suppose the following input is supplied to the program:***
  18.  
  19. ***D 300***
  20.  
  21. ***D 300***
  22.  
  23. ***W 200***
  24.  
  25. ***D 100***
  26.  
  27. ***Then, the output should be:***
  28.  
  29. ***500***
  30.  
  31.  
  32. ----------------------
  33. ### Hints:
  34. #### In case of input data being supplied to the question, it should be assumed to be a console input.
  35.  
  36. -------------------
  37. **Main author's Solution: Python 2**
  38. ```
  39. import sys
  40. netAmount = 0
  41. while True:
  42. s = raw_input()
  43. if not s:
  44. break
  45. values = s.split(" ")
  46. operation = values[0]
  47. amount = int(values[1])
  48. if operation=="D":
  49. netAmount+=amount
  50. elif operation=="W":
  51. netAmount-=amount
  52. else:
  53. pass
  54. print netAmount
  55. ```
  56. ----------------
  57. **My Solution: Python 3**
  58. ```
  59. ```
Add Comment
Please, Sign In to add comment