Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
def calculate():
    number_1 = int(input('Enter your first number: '))
    number_2 = int(input('Enter your second number: '))
    
    operation = input('''
    Enter an operator:
    + for addition
    - for subtraction
    * for multiplication
    / for division
    ''')
    
    if operation == '+':
      sum = number_1 + number_2
      print('{} + {} = '.format(number_1, number_2))
      print(sum)
    
    elif operation == '-':
      diff = number_1 - number_2
      print('{} - {} = '.format(number_1, number_2))
      print(diff)
    
    elif operation == '*':
      product = number_1 * number_2
      print('{} * {} = '.format(number_1, number_2))
      print(product)
    
    elif operation == '/':
      quotient = number_1 / number_2
      print('{} / {} = '.format(number_1, number_2))
      print(quotient)
    
    else:
        print('You have not typed a valid operator, please run the program again.')
      
calculate()

def recal(): 
    c = int(input('Enter the number: '))

    operation2 = input('''
    Enter an operator:
    + for addition
    - for subtraction
    * for multiplication
    / for division
    ''')

    if operation2 == '+':
      answer = sum + c 
      print('{} + {} = '.format(sum, c))
      print(answer)

    elif operation2 == '-':
      answer2 = diff - c 
      print('{} - {} = '.format(diff, c))
      print(answer2)

    elif operation2 == '*':
      answer3 = product * c
      print('{} * {} = '.format(product, c))
      print(answer3)

    elif operation2 == '/':
      answer4 = quotient / c
      print('{} / {} = '.format(quotient, c))
      print(answer4)

    else:
      print('You have not typed a valid operator, please run the program again.')

while True:    
    calc_again = input('''
Do you want to compute again?
Please type Y for YES or N for NO.
Type C if you want to continue.''')
    if calc_again == 'Y':
        calculate()

    elif calc_again == 'N':
        print('Thank You')
        

    elif calc_again == 'C':
      recal()
    
    else:
      print('END')


What I have tried:

I've tried nothing because I really don't know what to do at this point
Posted
Updated 5-Nov-21 0:50am
v2

At this point, a developper's approach is to investigate the issue.

Start by googling the error message: you will understand what is the issue.
Then, search for where it happens in your code. Generally at least the filename and the line number are displayed along with the error message; don't skip them, you need them to locate the issue.

Once you have done that, you find yourself closer to solution. More important, by doing that, you will get the skill to debug your code yourself, and that is an essential skill to a serious developper.
 
Share this answer
 
I gave you an answer yesterday in your original question at The num 1 and num 2 won't show and also how can I add the answer of the previous numbers to a new number[^], but you have decided on a different approach. Unfortunately you are not saving all your interim totals so you cannot add the new values to them. Go back to my answer of yesterday and see how to store a running total.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900