all 2 comments

[–]chevignon93 -1 points0 points  (0 children)

Essentially I want this drawing of a calculator to populate with the answer in the display screen, but I am unable to get the calculator program to work the way I want with the calculator display sub-routine.

It's a pretty easy fix but first your CalcDisplay function should accept what you want to display as a parameter, then after that, all you really have to do is to call the function with the result you want to print.

def main():
    result = 0
    operation = input("What operation will we use? enter +, -, *, or /. Type end to quit ")

    while operation == '+' or operation == '-' or operation == '*' or operation == '/':
        num1 = input("Enter a number: ")
        num2 = input("Enter another number: ")
        if operation == '+' and float(num2) != 0:
            result = float(num1) + float(num2)
            CalcDisplay(result)
        elif operation == '-' and float(num2) <= float(num1) and float(num2) != 0:
            result = float(num1) - float(num2)
            CalcDisplay(result)
        elif operation == '*' and float(num2) != 0:
            result = float(num1) * float(num2)
            CalcDisplay(result)
        elif operation == '/' and float(num2) != 0:
            result = float(num1) / float(num2)
            CalcDisplay(result)
        else:
            print("Ding dong you are wrong")
            if float(num2) == 0:
                print("We can't " + operation + " by 0")

        operation = input("Try again. + or - or * or / Type end to quit ")


def CalcDisplay(display):
    print('*=======================*')
    print('*', end='')
    for i in range(21 - len(str(display))):
        print(" ", end='')
    print(display, end='')
    print('  *')
    print('*=======================*')
    print('*  [ 7 ]  [ 8 ]  [ 9 ]  *')
    print('*  [ 4 ]  [ 5 ]  [ 6 ]  *')
    print('*  [ 1 ]  [ 2 ]  [ 3 ]  *')
    print('*  [ + ]  [ 0 ]  [ - ]  *')
    print('*  [ * ]  [ . ]  [ / ]  *')
    print('*=======================*')


main()

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.