Guest User

Untitled

a guest
Jan 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. # -*- coding: iso-8859-1 -*-
  2. # calcutron.py
  3.  
  4. while True:
  5. print "(a)dd, (s)ubtract, (m)ultiply, (d)ivide, (q)uit"
  6. operation = raw_input('Give an operation: ')
  7.  
  8. if operation == 'a' or operation == 's' or operation == 'm' or operation == 'd':
  9.  
  10. first = float(input('First number: '))
  11. second = float(input('Second number: '))
  12. if operation == 'a':
  13. result = first + second
  14. print '%.1f' %(result)
  15.  
  16. elif operation == 's':
  17. result = first - second
  18. print '%.1f' %(result)
  19.  
  20. elif operation == 'm':
  21. result = first * second
  22. print '%.1f' %(result)
  23.  
  24. elif operation == 'd':
  25. if second == 0:
  26. print "Cannot divide by zero."
  27. else:
  28. result = first / second
  29. print '%.1f' %(result)
  30.  
  31. elif operation == 'q':
  32. break
  33.  
  34. else:
  35. print "WHAT ARE YOU DOING?"
Add Comment
Please, Sign In to add comment