Skip to content

Commit 513ad4d

Browse files
add: calc with a very advanced automation concepts.
features: speech_recognition, auto_calculation, etc,..
1 parent 641e756 commit 513ad4d

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

advanced_calculator.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Program to make a simple calculator
2+
3+
from numbers import Number
4+
from sys import exit
5+
import colorama as color
6+
import inquirer
7+
from gtts import gTTS
8+
from pygame import mixer, time
9+
from io import BytesIO
10+
from pprint import pprint
11+
import art
12+
import date
13+
14+
15+
# Should be able to print date and time too.
16+
# Should use voice assistant for specially abled people.
17+
# A fully personalised calculator.
18+
# voice_assistant on/off , setting bool value to true or false
19+
20+
# Is the operations valid?
21+
22+
23+
# Validation checker
24+
class Calculator:
25+
def __init__(self):
26+
self.take_inputs()
27+
28+
def add(self):
29+
return self.num1 + self.num2
30+
31+
def sub(self):
32+
return self.num1 - self.num2
33+
34+
def multi(self):
35+
return self.num1 * self.num2
36+
37+
def div(self):
38+
return self.num1 / self.num2
39+
40+
def power(self):
41+
return self.num1**self.num2
42+
43+
def root(self):
44+
return self.num1 ** (1 / self.num2)
45+
46+
def remainer(self):
47+
return self.num1 % self.num2
48+
49+
def cube_root(self):
50+
return self.num1 ** (1 / 3)
51+
52+
def cube_exponent(self):
53+
return self.num1**3
54+
55+
def square_root(self):
56+
return self.num1 ** (1 / 2)
57+
58+
def square_exponent(self):
59+
return self.num1**2
60+
61+
def take_inputs(self):
62+
while True:
63+
while True:
64+
try:
65+
# self.num1 = float(input("Enter The First Number: "))
66+
# self.num2 = float(input("Enter The Second Number: "))
67+
pprint("Enter your number")
68+
# validation check must be done
69+
break
70+
except ValueError:
71+
pprint("Please Enter A Valid Number")
72+
continue
73+
# To let the user to know it is time to exit.
74+
pprint("Press 'q' to exit")
75+
# if self.num1 == "q" or self.num2 == "q":
76+
# exit() # Some how I need to exit it
77+
78+
def greeting(self):
79+
text_to_audio = "Welcome To The Calculator"
80+
self.gtts_object = gTTS(text=text_to_audio, lang="en", tld="co.in", slow=False)
81+
tts = self.gtts_object
82+
fp = BytesIO()
83+
tts.write_to_fp(fp)
84+
fp.seek(0) # Reset the BytesIO object to the beginning
85+
mixer.init()
86+
mixer.music.load(fp)
87+
mixer.music.play()
88+
while mixer.music.get_busy():
89+
time.Clock().tick(10)
90+
91+
# Here OOP is not followed.
92+
def user_name(self):
93+
self.name = input("Please enter your good name: ")
94+
# Making validation checks here
95+
text_to_audio = "{self.name}"
96+
self.gtts_object = gTTS(text=text_to_audio, lang="en", tld="co.in", slow=False)
97+
tts = self.gtts_object
98+
fp = BytesIO()
99+
tts.write_to_fp(fp)
100+
fp.seek(0) # Reset the BytesIO object to the beginning
101+
mixer.init()
102+
mixer.music.load(fp)
103+
mixer.music.play()
104+
while mixer.music.get_busy():
105+
time.Clock().tick(10)
106+
107+
def user_name_art(self):
108+
# Remove whitespaces from beginning and end
109+
# Remove middle name and last name
110+
# Remove special characters
111+
# Remove numbers
112+
f_name = self.name.split(" ")[0]
113+
f_name = f_name.strip()
114+
# Remove every number present in it
115+
# Will have to practice not logic
116+
f_name = "".join([i for i in f_name if not i.isdigit()])
117+
118+
# perform string operations on it for the art to be displayed.
119+
# Remove white spaces
120+
# Remove middle name and last name
121+
# Remove special characters
122+
# Remove numbers
123+
# Remove everything
124+
125+
126+
if __name__ == "__main__":
127+
operation_1 = Calculator(10, 5)
128+
129+
# Operations
130+
# User interaction
131+
# Study them properly and try to understand them.
132+
# Study them properly and try to understand them in very detailed length. Please.
133+
# Add a function to continually ask for input until the user enters a valid input.
134+
135+
136+
# Let's explore colorma

0 commit comments

Comments
 (0)