Skip to content

Instantly share code, notes, and snippets.

@edunham
Created January 15, 2014 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edunham/8445855 to your computer and use it in GitHub Desktop.
Save edunham/8445855 to your computer and use it in GitHub Desktop.
#! usr/bin/env python
# Hieronder volgt de code voor een rekenmachine waarbij aan de gebruiker
# de invoer van 2 getallen wordt gevraagd en welke operandor op de 2
# getallen toegepast moet worden
from time import sleep
def calculator(name):
print
print ('Well %s, what is the first number you would like to use?') %name
print
number1 = float(raw_input('Please insert yout first number: '))
print
print ('What is the second number that you would like to use?')
print
number2 = float(raw_input('Please insert your second number: '))
print
print ('What operation would you like to perform on these two numbers?')
print
print ('With this simple calculator you will have the following options:')
print ('1) Addition')
print ('2) Substraction')
print ('3) Multiplication')
print ('4) Division')
choice = raw_input('Which one will it be: ')
print ('')
choices = {'1':'+', '2':'-', '3':'*', '4':'/'}
print('Is it correct to assume that the operation you would like to perform is %s %s %s is?' %(number1, choices[choice], number2))
print
check = raw_input("Please answer 'yes' if this is correct and 'no'if it is not: ")
print
if 'yes' in check:
if choice == '1':
answer = float(number1) + float(number2)
print ('The answer is currently being calculated......')
print
sleep(1.5)
print ('The answer is %.4f') %answer
elif choice == '2':
answer = float(number1) - float(number2)
print ('The answer is currently being calculated......')
print
sleep(1.5)
print ('The answer is %.4f') %answer
elif choice == '3':
answer = float(number1) * float(number2)
print ('The answer is currently being calculated......')
print
sleep(1.5)
print ('The answer is %.4f') %answer
elif choice == '4':
answer = float(number1) / float(number2)
print ('The answer is currently being calculated......')
print
sleep(1.5)
print ('The answer is %.4f') %answer
else:
print('Perhaps we should try this again!')
print
calculator(name);
if __name__ == "__main__":
print ('What is your name? ')
print
name = raw_input('Please provide me with your first name: ')
calculator(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment