Python Forum

Full Version: Struggling for the past hour to define function and call it back
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok, so for the past hour i've been struggling to define a function and call it back, i dont know what im doing wrong i've done exactly how it says on google, i'm a beginner at Python, please show me how to do it.
Here is my code:


import sys
def operations():

calculation_input = input('''
Pentru adunare apasati +
Pentru scadere apasati -
Pentru inmultire apasati *
Pentru inmultire apasati /
Pentru inchiderea programului apasati 0
''')
if calculation_input == '0':
    sys.exit(0)
n1 = int(input('Introduce primul numar '))
n2 = int(input('Introduce al doilea numar '))
if calculation_input == '+':
    print('{} + {} = '.format(n1,n2))
    print(n1 + n2)
elif calculation_input == '-':
    print('{} - {} = '.format(n1,n2))
    print(n1 - n2)

elif calculation_input == '*':
    print('{} * {} = '.format(n1,n2))
    print(n1 * n2)
elif calculation_input == '/':
    print('{} / {} = '.format(n1,n2))
    print(n1 / n2)
else :
    print('Trebuie sa pui un simbol compatibil')
    sys.exit(0)

calculation_again = input('''vreti sa restartati programul?
da - se restarteaza
nu - nu se restarteaza
''')
if calculation_again == 'da':
    operations()
elif calculation_again == 'nu':
    sys.exit(0)
Are you wondering why nothing happens ?
Or what is the error message ?
Paul
Indentation is important in Python. The body of a function must be indented from the declaration, and the body of the function ends when indentation is less than or equal to the declaration
def declaration(arguments):
   body = arguments / 2
   return body

not_part_of_function = declaration(4)