SHOW:
|
|
- or go back to the newest paste.
| 1 | # Calculator in Python | |
| 2 | # -------------------- | |
| 3 | ||
| 4 | # -*-coding:UTF-8 -* | |
| 5 | ||
| 6 | import os | |
| 7 | ||
| 8 | # Introduction | |
| 9 | ||
| 10 | print ("Calclulator in Python\n")
| |
| 11 | print ("Available :\n")
| |
| 12 | print ("+\n-\n/\n*\n**\n%\n")
| |
| 13 | result = 0 | |
| 14 | stop = False | |
| 15 | choice = "" | |
| 16 | ||
| 17 | ||
| 18 | # Main Loop | |
| 19 | while stop == False: | |
| 20 | ||
| 21 | # Take Input | |
| 22 | # First Number | |
| 23 | ||
| 24 | while True: | |
| 25 | first_number = input("Enter First Number : ")
| |
| 26 | if first_number.isdigit(): | |
| 27 | first_number = float(first_number) | |
| 28 | break | |
| 29 | ||
| 30 | # Operation | |
| 31 | ||
| 32 | operation = input("Operation ? ")
| |
| 33 | ||
| 34 | # Second Number | |
| 35 | while True: | |
| 36 | second_number = input("Enter Second Number : ")
| |
| 37 | if second_number.isdigit(): | |
| 38 | second_number = float(second_number) | |
| 39 | break | |
| 40 | ||
| 41 | # Calculation | |
| 42 | ||
| 43 | if operation == "+": | |
| 44 | result = first_number + second_number | |
| 45 | elif operation == "-": | |
| 46 | result = first_number - second_number | |
| 47 | elif operation == "*": | |
| 48 | result = first_number * second_number | |
| 49 | elif operation == "/": | |
| 50 | result = first_number / second_number | |
| 51 | elif operation == "**": | |
| 52 | result = first_number ** second_number | |
| 53 | elif operation == "%": | |
| 54 | result = first_number % second_number | |
| 55 | else: | |
| 56 | - | print ("Ce n'est pas une operation !")
|
| 56 | + | print ("That's not an operation !")
|
| 57 | ||
| 58 | # Result | |
| 59 | ||
| 60 | print (first_number," ",operation," ",second_number," equals: ",result,".") | |
| 61 | ||
| 62 | # Asking for ReCalculation | |
| 63 | choice = input("Do you want to start over ?(O/N): ")
| |
| 64 | if choice == "O": | |
| 65 | continue | |
| 66 | else: | |
| 67 | stop = True | |
| 68 | ||
| 69 | ||
| 70 | ||
| 71 | os.system("pause") |