Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math, operator
- def main():
- print '\nHello and welcome to my calculator!'
- operators = {
- '+': operator.add,
- '-': operator.sub,
- '*': operator.mul,
- '/': operator.truediv,
- 'sine': math.sin
- }
- while 1:
- function = raw_input('\nPlease input the function you would' +
- 'like to use. These include +, -, *, /, sine.\n')
- try:
- op = operators[function]
- except:
- print 'Sorry, that is an incorrect function.'
- continue
- if op != math.sin:
- print '\nNow please input the two variables.'
- firstnum = float(raw_input())
- secondnum = float(raw_input())
- answer = op(firstnum, secondnum)
- else:
- print '\nPlease enter the angle.'
- angle = float(raw_input())
- answer = math.sin(angle)
- print 'Your answer is %f ' % answer
- print '\nWhen you are ready to quit, simply press Ctrl + C'
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement