Created
January 15, 2014 22:19
-
-
Save edunham/8445855 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! 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 ('Well %s, what is the first number you would like to use?') %name | |
number1 = float(raw_input('Please insert yout first number: ')) | |
print ('What is the second number that you would like to use?') | |
number2 = float(raw_input('Please insert your second number: ')) | |
print ('What operation would you like to perform on these two numbers?') | |
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)) | |
check = raw_input("Please answer 'yes' if this is correct and 'no'if it is not: ") | |
if 'yes' in check: | |
if choice == '1': | |
answer = float(number1) + float(number2) | |
print ('The answer is currently being calculated......') | |
sleep(1.5) | |
print ('The answer is %.4f') %answer | |
elif choice == '2': | |
answer = float(number1) - float(number2) | |
print ('The answer is currently being calculated......') | |
sleep(1.5) | |
print ('The answer is %.4f') %answer | |
elif choice == '3': | |
answer = float(number1) * float(number2) | |
print ('The answer is currently being calculated......') | |
sleep(1.5) | |
print ('The answer is %.4f') %answer | |
elif choice == '4': | |
answer = float(number1) / float(number2) | |
print ('The answer is currently being calculated......') | |
sleep(1.5) | |
print ('The answer is %.4f') %answer | |
else: | |
print('Perhaps we should try this again!') | |
calculator(name); | |
if __name__ == "__main__": | |
print ('What is your name? ') | |
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