Advertisement
Guest User

challenge05.py

a guest
Feb 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import requests
  2. import json
  3.  
  4. chall_url = "https://cc.the-morpheus.de/challenges/5/"
  5. solution_url = "https://cc.the-morpheus.de/solutions/5/"
  6.  
  7. inputStr = requests.get(chall_url).text
  8. inputList = inputStr.split(' ')
  9. length = len(inputList)
  10.  
  11. stack = []
  12.  
  13. for i in range(length):
  14.     elem = inputList[i]
  15.     if elem.isnumeric():
  16.         stack.append(int(elem))
  17.     else:
  18.         b = stack.pop()
  19.         a = stack.pop()
  20.         if elem == '+':
  21.             c = a + b
  22.         elif elem == '-':
  23.             c = a - b
  24.         elif elem == '*':
  25.             c = a * b
  26.         elif elem == '/':
  27.             c = a / b
  28.         stack.append(c)
  29.  
  30. solution = int(stack.pop())
  31.  
  32.  
  33. def sendResult(solution):
  34.     data = {"token": solution}
  35.     result = requests.post(solution_url, json.dumps(data))
  36.     print(result.text)
  37.  
  38. sendResult(solution)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement