Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: iso-8859-1 -*-
- def add(a, b):
- c = a + b
- return c
- def subtract(a, b):
- c = a - b
- return c
- def multiply(a, b):
- c = a * b
- return c
- def divide(a, b):
- if b != 0:
- c = a / b
- return c
- else:
- print "Cannot divide by zero."
- return None
- def main():
- loop = True
- while loop:
- print "(a)dd, (s)ubtract, (m)ultiply, (d)ivide, (q)uit"
- operation = raw_input("Give an operation: ")
- if operation == "q":
- loop = False
- elif operation in ("a", "s", "m", "d"):
- first = float(raw_input("First number: "))
- second = float(raw_input("Second number: "))
- if operation == "a":
- tulos = add(first, second)
- print "%.1f" %(tulos)
- continue
- elif operation == "s":
- tulos = subtract(first, second)
- print "%.1f" %(tulos)
- continue
- elif operation == "m":
- tulos = multiply(first, second)
- print "%.1f" %(tulos)
- continue
- elif operation == "d":
- tulos = divide(first, second)
- if tulos == (None):
- continue
- else:
- print "%.1f" %(tulos)
- continue
- else:
- print "WHAT ARE YOU DOING?"
- continue
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment