Answer to Question #349393 in Python for Bunny

Question #349393

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.

1
Expert's answer
2022-06-09T18:21:46-0400
# 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}')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS