Show DevBest [PY] Calculator 2

Sway

Ruby and Python are married.
Dec 19, 2010
194
76
The last thing DevBest needs is another calculator script. No one uses these as an every day calculator (or at least I hope not) but I figured that it does help some of you who are trying to learn how to create scripts like these.

Three months ago I released a calculator which was horrible. I looked back at it and found ways that I could improve it...

Old version:


New version:


Putting the two scripts side by side, you could definitely see the difference. If anyone does use this to learn or base another script off of, use the newer version. I will be constantly updating it with newer features. It currently has the basic four functions (addition, subtraction, multiplication, division) and it can also calculate the factorial and square root of a number.

Snippet:
Code:
    operation = input(">").lower()
    operation_choices = ['a','s','m','d','factorial','sqrt']

    if operation in operation_choices[:4]:
        number1 = input("Number 1: ")
        number2 = input("Number 2: ")
        if operation in operation_choices[0]:
            addition(number1,number2)
            exit_calculator()
        elif operation in operation_choices[1]:
            subtraction(number1,number2)
            exit_calculator()
        elif operation in operation_choices[2]:
            multiplication(number1,number2)
            exit_calculator()
        elif operation in operation_choices[3]:
            division(number1,number2)
            exit_calculator()
        else:
            print("Restart the program until I figure out how to loop this.")

Thanks.
 

Users who are viewing this thread

Top