Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
[PY] Calculator
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Sway" data-source="post: 223914" data-attributes="member: 1889"><p>This is an extremely simple calculator I cooked up in <strong>Python </strong>out of boredom.</p><p> </p><p><strong>Source</strong>:</p><p><a href="http://pastebin.com/60vUy9XW" target="_blank">http://pastebin.com/60vUy9XW</a></p><p> </p><p><strong>Snippet</strong>:</p><p>[CODE]def main():</p><p> choices = ['a', 's', 'm', 'd']</p><p> print("Would you like to add [A], subtract [S], multiply [M], or divide [D]?")</p><p> choice = input()</p><p> </p><p> if choice.lower() == choices[0]:</p><p> print()</p><p> add()</p><p> elif choice.lower() == choices[1]:</p><p> print()</p><p> subtract()</p><p> elif choice.lower() == choices[2]:</p><p> print()</p><p> multiply()</p><p> elif choice.lower() == choices[3]:</p><p> print()</p><p> divide()</p><p> else:</p><p> print("I didn't get that..")</p><p> time.sleep(2)</p><p> main()[/CODE]</p><p> </p><p>It took me about 30 minutes to create and so far only has addition, subtraction, division and multiplication. I do wish to add other stuff (square root, exponential, etc.) later on.</p><p> </p><p>It has no true exception handling so far.</p><p> </p><p>The code can be made more efficient.</p><p></p><p><strong>UPDATE:</strong></p><p>** Made the interface much nicer.</p><p>** Added the option to quit the program from the start of the program (you could have only exited out after you performed an action like add).</p><p> </p><p><strong>Source:</strong></p><p><a href="http://pastebin.com/2Fu5SmEG" target="_blank">http://pastebin.com/2Fu5SmEG</a></p><p> </p><p><strong>Snippet:</strong></p><p>[CODE]def main():</p><p> choices = ['1', '2', '3', '4']</p><p> quit1 = 'Q'</p><p> print()</p><p> print()</p><p> </p><p> print("""</p><p>Enter a number to perform that action.</p><p> </p><p>[1] Addition</p><p>[2] Subtraction</p><p>[3] Multiplication</p><p>[4] Division</p><p> </p><p>[Q] Quit.</p><p>""")</p><p> choice = input("> ")</p><p> </p><p> if choice.lower() == choices[0]:</p><p> print()</p><p> add()</p><p> elif choice.lower() == choices[1]:</p><p> print()</p><p> subtract()</p><p> elif choice.lower() == choices[2]:</p><p> print()</p><p> multiply()</p><p> elif choice.lower() == choices[3]:</p><p> print()</p><p> divide()</p><p> elif choice.lower() == quit1:</p><p> print()</p><p> print("Ending program...")</p><p> time.sleep(2)</p><p> os._exit(1)</p><p> </p><p> else:</p><p> print()</p><p> print("I didn't get that..")</p><p> time.sleep(2)</p><p> main()[/CODE]</p><p> </p><p>I will be using CMath for the following updates to calculate the <strong>square root, exponential values, complex numbers, logarithms, etc.</strong></p><p> </p><p>I also plan on implementing NumPy to calculate <strong>linear equations</strong> and such much easier.</p></blockquote><p></p>
[QUOTE="Sway, post: 223914, member: 1889"] This is an extremely simple calculator I cooked up in [B]Python [/B]out of boredom. [B]Source[/B]: [URL]http://pastebin.com/60vUy9XW[/URL] [B]Snippet[/B]: [CODE]def main(): choices = ['a', 's', 'm', 'd'] print("Would you like to add [A], subtract [S], multiply [M], or divide [D]?") choice = input() if choice.lower() == choices[0]: print() add() elif choice.lower() == choices[1]: print() subtract() elif choice.lower() == choices[2]: print() multiply() elif choice.lower() == choices[3]: print() divide() else: print("I didn't get that..") time.sleep(2) main()[/CODE] It took me about 30 minutes to create and so far only has addition, subtraction, division and multiplication. I do wish to add other stuff (square root, exponential, etc.) later on. It has no true exception handling so far. The code can be made more efficient. [B]UPDATE:[/B] ** Made the interface much nicer. ** Added the option to quit the program from the start of the program (you could have only exited out after you performed an action like add). [B]Source:[/B] [URL]http://pastebin.com/2Fu5SmEG[/URL] [B]Snippet:[/B] [CODE]def main(): choices = ['1', '2', '3', '4'] quit1 = 'Q' print() print() print(""" Enter a number to perform that action. [1] Addition [2] Subtraction [3] Multiplication [4] Division [Q] Quit. """) choice = input("> ") if choice.lower() == choices[0]: print() add() elif choice.lower() == choices[1]: print() subtract() elif choice.lower() == choices[2]: print() multiply() elif choice.lower() == choices[3]: print() divide() elif choice.lower() == quit1: print() print("Ending program...") time.sleep(2) os._exit(1) else: print() print("I didn't get that..") time.sleep(2) main()[/CODE] [B] [/B] I will be using CMath for the following updates to calculate the [B]square root, exponential values, complex numbers, logarithms, etc.[/B] I also plan on implementing NumPy to calculate [B]linear equations[/B] and such much easier. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
[PY] Calculator
Top