![]() |
Struggling for the past hour to define function and call it back - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Struggling for the past hour to define function and call it back (/thread-30643.html) |
Struggling for the past hour to define function and call it back - godlyredwall - Oct-29-2020 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) RE: Struggling for the past hour to define function and call it back - DPaul - Oct-29-2020 Are you wondering why nothing happens ? Or what is the error message ? Paul RE: Struggling for the past hour to define function and call it back - deanhystad - Oct-29-2020 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) |