BASIC CALCULATOR Program in Python
Program:
user_input = input("Enter your expression:")
changed_input = ''
for i in user_input:
if i != ' ':
changed_input += i
first_part = ''
second_part = ''
third_part = ''
for j in range(len(changed_input)):
if changed_input[j].isdigit():
pass
else:
break
len_check = 0
for k in changed_input:
if k.isdigit():
len_check += 1
operator_len = len(changed_input) - len_check
def add():
print(first_part + third_part)
def sub():
print(first_part - third_part)
def mul():
print(first_part * third_part)
def div():
print(first_part / third_part)
def pow():
print(first_part ** third_part)
def flo():
print(first_part // third_part)
if operator_len == 2:
first_part = int(changed_input[:j])
second_part = changed_input[j: j + 2]
third_part = int(changed_input[j + 2:])
if second_part == '**':
pow()
elif second_part == '//':
flo()
else:
print("Use any one of these operators [+, -, *, /, **, //]")
elif operator_len == 1:
first_part = int(changed_input[:j])
second_part = changed_input[j: j + 1]
third_part = int(changed_input[j + 1:])
if second_part == '+':
add()
elif second_part == '-':
sub()
elif second_part == '*':
mul()
elif second_part == '/':
div()
else:
print("Use any one of these operators [+, -, *, /, **, //]")
Programmer details : Arun Meyyappan PL
Software used: Visual studio CODE
Version : 1.74.3
Documents and files download link
Python File(.py)
Text File(.txt)
0 Comments