python - Regarding passing variables to an argument -


i working in python 2.7.8.

i'm learning parameters , methods. i'm trying accomplish have user enter 2 different variables pass them argument within different methods, sum() , difference().

my following code this:

def computesum(x, t):     x = int(raw_input('please enter integer: '))     t = int(raw_input('please enter second integer: '))     x+t return sum  def computedif(y, j):     y = int(raw_input('please enter integer: '))     j = int(raw_input('please enter second integer: '))     y+j return dif  def main():     raw_input('would find sum of 2 numbers or difference of 2 numbers?: ')     answer = 'sum' while true:     computesum() else:     computedif() 

for reason compiler (pyscriptor) isn't running , cannot see output nor error messages, blank. can possibly me syntax/logic errors?

there few problems code

  • your indentation way off

  • computesum , computedif expect 2 numbers parameters, ask them terminal

  • you return variables sum , dif, never assign values them

  • you call either computesum or computedif, never returned value

  • you never call main. know don't need main function? can put code in line after function definitions

this little closer had in mind

def computesum(x, t):     return x + t  def computedif(y, j):     return y - j  def main():     while true:         answer = raw_input('would find "sum" of 2 numbers or "dif"ference of 2 numbers? ')         = int(raw_input('please enter integer: '))         b = int(raw_input('please enter second integer: '))          if answer == 'sum':             print(computesum(a, b))         elif answer == 'dif':             print(computedif(a, b))         else:             print('please enter "sum" or "dif"')  main() 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -