Create any program using python programming language. Use at least 10 Python built-in functions. Submit the program file of your program ( .py) for those who uses desktop or laptop in code and screenshot of the code and output for those who uses phones to code.
# I wrote this calculator in courses,
# and it should contain a sufficient number of built-in python functions,
# if something is missing, let me know
counter_for_while = 0
print("it's a simple calculator, to stop operations, write 'stop'")
result = []
while True:
a = input('Enter the first number')
if a == 'stop':
print(f'Number of operations performed:{counter_for_while}')
print(f'results of operations{result}')
break
else:
try:
number_1 = float(a)
except ValueError:
print("Invalid value, enter a dotted digit or 'stop'")
continue
my_operators = input('Enter operator (+, -, /, *, mod, pow, div)')
if my_operators == 'stop':
print(f'Number of operations performed:{counter_for_while}')
print(f'results of operations{result}')
break
b = input('Enter the second number')
if b == 'stop':
print(f'Number of operations performed:{counter_for_while}')
print(f'results of operations{result}')
break
else:
try:
number_2 = float(b)
except ValueError:
print("Invalid value, enter a dotted digit or 'stop'")
continue
counter = 0
if my_operators == '+':
counter = sum([number_1, number_2])
elif my_operators == '-':
counter = number_1 - number_2
elif my_operators == '/':
try:
counter = number_1 / number_2
except ZeroDivisionError:
print('Division by zero')
continue
elif my_operators == '*':
counter = number_1 * number_2
elif my_operators == 'mod':
try:
counter = number_1 % number_2
except ZeroDivisionError:
print('Taking zero remainder from division')
continue
elif my_operators == 'pow':
counter = pow(number_1, number_2)
elif my_operators == 'div':
try:
counter = number_1 // number_2
except ZeroDivisionError:
print('Integer division by zero')
continue
else:
print('You entered an invalid operator, please try again')
continue
if counter.is_integer():
print(int(counter))
result.append(int(counter))
else:
a = round(counter, 1)
print(float(a))
result.append(a)
counter_for_while += 1
print(f'Number of operations performed:{counter_for_while}')
print(f'results of operations{result}')
Comments
Leave a comment