Advertisement
Guest User

Untitled

a guest
Mar 18th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import math, operator
  2.  
  3. def main():
  4. print '\nHello and welcome to my calculator!'
  5.  
  6. operators = {
  7. '+': operator.add,
  8. '-': operator.sub,
  9. '*': operator.mul,
  10. '/': operator.truediv,
  11. 'sine': math.sin
  12. }
  13.  
  14. while 1:
  15. function = raw_input('\nPlease input the function you would' +
  16. 'like to use. These include +, -, *, /, sine.\n')
  17.  
  18. try:
  19. op = operators[function]
  20. except:
  21. print 'Sorry, that is an incorrect function.'
  22. continue
  23.  
  24. if op != math.sin:
  25. print '\nNow please input the two variables.'
  26. firstnum = float(raw_input())
  27. secondnum = float(raw_input())
  28. answer = op(firstnum, secondnum)
  29. else:
  30. print '\nPlease enter the angle.'
  31. angle = float(raw_input())
  32. answer = math.sin(angle)
  33.  
  34. print 'Your answer is %f ' % answer
  35. print '\nWhen you are ready to quit, simply press Ctrl + C'
  36.  
  37. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement