-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1st_project_py.py
More file actions
82 lines (70 loc) · 2.49 KB
/
1st_project_py.py
File metadata and controls
82 lines (70 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""1st Project .py
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/19CUYpYvE_XuqZJxCJwkqho_ONCMm8b33
"""
import sys
import time
import math
def slow_print(text, delay=0.05):
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(delay)
sys.stdout.write('\n')
sys.stdout.flush()
slow_print("| Welcome To Calculator App |")
time.sleep(0.5)
slow_print("| Choose an operation (+,-,/,*,%,//,**,√) |")
operation = input().strip()
if operation == "√":
try:
num_for_sqrt = float(input("| Enter the number for square root: "))
if num_for_sqrt < 0:
slow_print("Error: Cannot calculate square root of a negative number!")
else:
result = math.sqrt(num_for_sqrt)
slow_print(f"Square root of {num_for_sqrt} = {result}")
except ValueError:
slow_print("Please input an integer or float number.")
elif operation in ['+', '-', '*', '/', '%', '//', '**']:
try:
num1 = float(input("| Enter First number: "))
num2 = float(input("| Enter Second number: "))
if operation == "+":
result = num1 + num2
slow_print(f"{num1} + {num2} = {result}")
elif operation == "-":
result = num1 - num2
slow_print(f"{num1} - {num2} = {result}")
elif operation == "*":
result = num1 * num2
slow_print(f"{num1} * {num2} = {result}")
elif operation == "/":
if num2 != 0:
result = num1 / num2
slow_print(f"{num1} / {num2} = {result}")
else:
slow_print("Error: Can't divide by zero!")
elif operation == "%":
if num2 != 0:
result = num1 % num2
slow_print(f"{num1} % {num2} = {result}")
else:
slow_print("Error: Can't modulo by zero!")
elif operation == "//":
if num2 != 0:
result = num1 // num2
slow_print(f"{num1} // {num2} = {result}")
else:
slow_print("Error: Can't divide by zero!")
elif operation == "**":
result = num1 ** num2
slow_print(f"{num1} ** {num2} = {result}")
except ValueError:
slow_print("Please input an integer or float for both numbers.")
else:
slow_print(f"Invalid Operation {operation}")
else:
slow_print(f"Invaild Operation {operation}")