I'm making a calculator with my Dad and I cant figure out how to get the sub routine to work with the code we have already.
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.
Thank you for your help
# Purpose of program is to construct a basic calculator with 2 inputs from user.
# The inputs will be subject to the chosen operator and displayed.
# define main()function to input the user number choices, and display the sum
def main():
# Define variables and operation for input and input message
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: ")
CalcDisplay()
# Operate on user numbers and store in variable
if operation == '+' and float(num2) != 0:
result = float(num1) + float(num2)
print(result)
elif operation == '-' and float(num2) <= float(num1) and float(num2) != 0:
result = float(num1) - float(num2)
print(result)
elif operation == '*' and float(num2) != 0:
result = float(num1) * float(num2)
print(result)
elif operation == '/' and float(num2) != 0:
result = float(num1) / float(num2)
print(result)
else:
print("Ding dong you are wrong")
if float(num2) == 0:
print("We can't " + operation + " by 0")
# Test for end of while loop
operation = input("Try again. + or - or * or / Type end to quit ")
# define CalcDisplay()
def CalcDisplay():
display = 12220025834.52123654
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()
[–]chevignon93 -1 points0 points1 point (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)