Python Forum
Struggling for the past hour to define function and call it back
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Struggling for the past hour to define function and call it back
#1
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)
metulburr write Oct-29-2020, 02:16 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Are you wondering why nothing happens ?
Or what is the error message ?
Paul
Reply
#3
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  list call problem in generator function using iteration and recursive calls postta 1 153 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 335 Oct-06-2020, 03:58 PM
Last Post: snippsat
  Help with define a def function Omer_ 3 198 Sep-20-2020, 06:59 PM
Last Post: Omer_
  function not giving back total SephMon 1 319 Aug-25-2020, 12:46 PM
Last Post: deanhystad
  struggling with != statements CallumRoberts2004 2 203 Aug-18-2020, 03:01 PM
Last Post: GOTO10
  How to define a function to create a resorted list? sparkt 6 414 Aug-08-2020, 04:10 PM
Last Post: sparkt
  How to call/read function for all elements in my list in python johnny_sav1992 1 308 Jul-27-2020, 04:19 PM
Last Post: buran
  I’m Flat out struggling to understand list indexes gr3yali3n 7 443 Jul-20-2020, 07:18 PM
Last Post: princetonits
  Struggling with nested list gr3yali3n 3 368 Jul-09-2020, 05:30 PM
Last Post: DPaul
  Python: Call function with variabele? Ending in error. efclem 5 458 Apr-22-2020, 02:35 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020