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
  The function of double underscore back and front in a class function name? Pedroski55 9 562 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  Why can't I copy and past only ONE specific tab? NewWorldRonin 8 694 Jan-12-2024, 06:31 PM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 752 May-02-2023, 08:40 AM
Last Post: Gribouillis
  Struggling with Juggling JSON Data SamWatt 7 1,820 May-09-2022, 02:49 AM
Last Post: snippsat
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 1,421 Apr-06-2022, 03:41 PM
Last Post: Gribouillis
  Needing to Check Every Quarter Hour bill_z 10 2,894 Feb-09-2022, 07:23 PM
Last Post: menator01
  Date format and past date check function Turtle 5 4,068 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Need to run 100+ Chrome’s with Selenium but can’t get past ~15 without breaking imillz 0 1,322 Sep-04-2021, 04:51 PM
Last Post: imillz
  Syntax errors: Struggling to setup enviroment and load packages AH56 5 2,724 Jun-30-2021, 01:01 PM
Last Post: AH56
  how to call an object in another function in Maya bstout 0 2,042 Apr-05-2021, 07:12 PM
Last Post: bstout

Forum Jump:

User Panel Messages

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